https://blog.csdn.net/chenhaifeng2016/article/details/71374876
Kubernetes的总体架构
master | 10.30.30.104 | centos 7.3 64位 | Master |
node1 | 10.30.30.126 | centos 7.3 64位 | Node |
node2 | 10.30.30.129 | centos 7.3 64位 | Node |
关闭防火墙或开通相关端口,测试环境部署推荐先关闭防火墙服务。
systemctl stop firewalld
systemctl disable firewalld
停止SELinux。
编辑文件/etc/selinux/config
容器引擎docker的部署
yum install docker,切记不要安装docker-ce,kubernetes1.6.2目前不支持docker-ce.
部署etcd3,也可以 yum install etcd 方便
http://blog.csdn.net/chenhaifeng2016/article/details/71122886
跨主机容器间网络通信采用flannel vxlan,也可以 yum install flannel 方便
http://blog.csdn.net/chenhaifeng2016/article/details/71480249
封包方式影响性能,不建议用于生产环境。如果对性能有要求,建议采用路由方案,比如calico。
部署Kubernetes
下载软件包
wget https://github.com/kubernetes/kubernetes/releases/download/kubernetes-server-linux-amd64.tar.gz
tar zxvf kubernetes-server-linux-amd64.tar.gz
cp kubelet kubectl kube-proxy kubelet kube-scheduler kube-controller-manager kube-apiserver /usr/bin
定义kube-apiserver.service
master:节点
[Unit]
Description=Kube-apiserver Service
After=network.target
After=etcd.service
After=docker.service
After=flanneld.service
[Service]
Type=notify
ExecStart=/usr/bin/kube-apiserver \
--allow-privileged=true \
--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota \
--etcd-servers=http://10.30.30.104:2379 \
--advertise-address=10.30.30.104 \
--bind-address=10.30.30.104 \
--insecure-bind-address=0.0.0.0 \
--log-dir=/usr/local/src/kubernetes/log/kube-apiserver \
--logtostderr=false \
--service-cluster-ip-range=10.254.0.0/16 \
--v=0
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
定义kube-controller-manager.service
[Unit]
Description=Kube-controller-manager Service
After=network.target
After=docker.service
After=etcd.service
After=flanneld.service
[Service]
ExecStart=/usr/bin/kube-controller-manager \
--logtostderr=false \
--log-dir=/usr/local/src/kubernetes/log/kube-controller-manager \
--master=http://0.0.0.0:8080 \
--service-cluster-ip-range=10.254.0.0/16 \
--leader-elect=true \
--v=0
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
定义kube-scheduler.service
[Unit]
Description=Kube-scheduler Service
After=network.target
After=docker.service
After=etcd.service
After=flanneld.service
[Service]
ExecStart=/usr/bin/kube-scheduler \
--log-dir=/usr/local/src/kubernetes/log/kube-scheduler \
--logtostderr=false \
--master=http://0.0.0.0:8080 \
--leader-elect=true \
--v=0
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
安装以及运行服务
cp *.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start kube-apiserver kube-controller-manager kube-scheduler
systemctl status kube-apiserver kube-controller-manager kube-scheduler
systemctl enable kube-apiserver kube-controller-manager kube-scheduler
配置Node (注意事项:不同的Node配置不同的IP地址)
节点node2不部署kubelet和kube-proxy.
创建kubelet.service
[Unit]
Description=Kubelet Service
After=network.target
After=docker.service
After=etcd.service
After=flanneld.service
[Service]
ExecStart=/usr/bin/kubelet \
--api-servers=http://10.0.0.201:8080 \
--log-dir=/usr/local/src/kubernetes/log/kubelet \
--logtostderr=false \
--address=10.30.30.129 \
--hostname-override=10.30.30.129 \
--allow-privileged=true \
--pod-infra-container-image=docker.io/wangyanbin/pause-amd64:3.0 \
--v=0 \
--cgroup-driver=systemd
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
创建kube-proxy.service
[Unit]
Description=Kube-proxy Service
After=network.target
After=docker.service
After=etcd.service
After=flanneld.service
[Service]
ExecStart=/usr/bin/kube-proxy \
--log-dir=/usr/local/src/kubernetes/log/kube-proxy \
--logtostderr=false \
--master=http://10.30.30.104:8080 \
--v=0 \
--bind-address=10.30.30.129 \
--hostname-override=10.30.30.129 \
--cluster-cidr=10.254.0.0/16
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
cp *.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start kubelet kube-proxy
systemctl status kubelet kube-proxy
systemctl enable kubelet kube-proxy
验证结果
测试服务
kubectl run nginx --replicas=2 --labels="run=load-balancer-example" --image=nginx --port=80
kubectl expose deployment nginx --type=NodePort --name=example-service
kubectl describe svc example-service
访问nginx
通过Node IP和Node Port访问服务
curl 10.0.0.202:32360
curl 10.0.0.203:32360
通过Pod IP访问服务
curl 172.30.73.2:80
curl 172.30.8.2:80
在kubernetes集群范围内通过Service IP访问服务。一个微服务对应一个虚拟的ServiceIP,这是一个很巧妙的设计。
curl 10.254.253.118:80 (只能在节点node202和node203运行,因为需要kube-proxy)
接下来部署kube-DNS, Ingress controller, WebUI Dashboard, heapster监控, prometheus监控,EFK日志, Helm等功能。