谈到kubernetes(或者说k8s)不得不提到云计算、虚拟化以及容器技术,相关介绍网上一大堆,不再赘述。而kubernetes的出现就是为了高效的管理云端运行的docker容器。
环境
docker 1.30 ----------docker的安装请参考官方文档
golang 1.8.3 ----------自行百度
etcd 3.2.5 --------------安装文档参考官方文档
kubernetes 1.6.8 ---稍后介绍
部署方案
master+etcd 10.0.45.44 node1 10.0.48.50 node2 10.0.48.59
安装和配置
从github.com/kubernetes/kubernetes上下载1.6.8已编译好的二进制文件
tar xzvf kubernetes.tar.gz
cd kubernetes
./cluster/get-kube-binaries.sh
执行该shell会自动下载kube的server和client可执行文件,其中客户端文件会自动安装在kubernetes目录下的client文件夹下,服务端文件会安装在kubernetes/server/kubernetes/server/bin/下面(包含客户端文件)
master节点需要:kube-apiserver, kube-controller-manager, kube-scheduler
node节点需要:kubelet和kube-proxy
这些程序我们通过systemctl的方式来进行管理(包括etcd)
1、master配置
kube-etcd.service
[Unit] Description=Kube-etcd Service After=network.target [Service] Type=notify ExecStart=/usr/local/bin/etcd --name "etcd1" --data-dir="~/.k8s/etcd" --listen-client-urls="http://10.0.45.44:2379,http://127.0.0.1:2379" --listen-peer-urls="http://10.0.45.44:2380" --advertise-client-urls="http://10.0.45.44:2379" --initial-advertise-peer-urls="http://10.0.45.44:2380" --initial-cluster="etcd1=http://10.0.45.44:2380" --initial-cluster-state="new" Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
kube-apiserver.service
[Unit] Description=Kube-apiserver Service After=network.target [Service] Type=notify ExecStart=/usr/local/bin/kube-apiserver --admission-control=NamespaceAutoProvision,LimitRanger,SecurityContextDeny --apiserver-count=1 --cors-allowed-origins=.* --enable-garbage-collector=false --etcd-servers=http://10.0.45.44:2379 --insecure-bind-address=0.0.0.0 --insecure-port=8080 --log-dir=~/.kube/log/kube-apiserver --logtostderr=false --service-cluster-ip-range=10.0.0.0/16 --v=5 Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
kube-controller-manager.service
[Unit] Description=Kube-controller-manager Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/kube-controller-manager --enable-garbage-collector=false --logtostderr=false --log-dir=~/.kube/log/kube-controller-manager --pod-eviction-timeout=5m0s --master=http://0.0.0.0:8080 --node-monitor-grace-period=40s --terminated-pod-gc-threshold=12500 --leader-elect=true --v=4 Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
kube-scheduler.service
[Unit] Description=Kube-scheduler Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/kube-scheduler --log-dir=~/.k8s/log/kube-scheduler --logtostderr=false --master=http://0.0.0.0:8080 --leader-elect=true --v=5 Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
注意修改自己的IP地址,下面启动服务……
//add to path
cd etcd-v3.2.5-linux-amd64; sudo cp -rf etcd /usr/local/bin
cd kubernetes/server/kubernetes/server/bin/; sudo cp -rf kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin
sudo cp -rf kube-etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service /lib/systemd/system/
//start server
sudo -i
systemctl --system daemon-reload
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
2. node 1
kubelet.service
[Unit] Description=Kubelet Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/kubelet --api-servers=http://10.0.45.44:8080 --hostname-override=10.0.48.50 --image-gc-high-threshold=80 --image-gc-low-threshold=50 --log-dir=~/.k8s/log/kubelet --logtostderr=false --pod-infra-container-image=docker.cloudin.com/google_containers/pause-amd64:3.0 --system-reserved cpu=2000m,memory=4G --v=5 Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
kube-proxy.service
[Unit] Description=Kube-proxy Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/kube-proxy --log-dir=~/.k8s/log/kube-proxy --logtostderr=false --master=http://10.0.48.50:8080 --v=5 Restart=always LimitNOFILE=65536 [Install] WantedBy=default.target
node 2需要将相应ip地址中的10.0.48.50改为10.0.48.59
下面启动服务……
//add to path
cd kubernetes/server/kubernetes/server/bin/; sudo cp -rf kubelet kube-proxy /usr/local/bin sudo cp -rf kubelet.service kube-proxy.service /lib/systemd/system/
//start
sudo -i
systemctl --system daemon-reload
systemctl start kubelet.service
systemctl start kube-proxy.service
3、测试环境是否搭建成功
$kubectl get nodes NAME STATUS AGE VERSION 10.0.48.50 NotReady 1h v1.6.8 10.0.48.59 Ready 1h v1.6.8
$kubectl get service NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.0.0.1 <none> 443/TCP 1h
------------------------------------------THIS IS AN END LINE, HAVE FUN-------------------------------------------------------------