1 集群部署
1.1 Master组件和Node组件
1.2 Master组件的apiserver, controller-manager, scheduler
1.3 Node组件的kubelet(创建容器), proxy(网络代理)
1.4安装证书
[root@localhost ~]# mkdir ssl
[root@localhost ~]# cd ssl
[root@localhost ssl]# wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
[root@localhost ssl]# wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
[root@localhost ssl]# wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
[root@localhost ssl]# chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64
[root@localhost ssl]# mv cfssl-certinfo_linux-amd64 /usr/local/bin/cfssl
[root@localhost ssl]# mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
[root@localhost ssl]# mv cfssl_linux-amd64 /usr/local/bin/cfssl-certinfo
1.5操作命令
kubectl get node
kubectl run nginx --image=nginx --replicas=3
kubectl get pod
kubectl get all
kubectl get pod -o wide
//暴露接口
kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort
1.6实战
1.6.1配置master节点
[root@localhost ~]# unzip master.zip
[root@localhost ~]# chmod +x * //授予权限
[root@localhost ~]# mkdir /opt/kubernetes/{bin,cfg} -p //创建双目录
[root@localhost ~]# mv kube* /opt/kubernetes/bin/ //移动
[root@localhost ~]# vi apiserver.sh //查看脚本
[root@localhost ~]# apt-get install etcd -y
[root@localhost ~]# vi /etc/default/etcd //编写etcd
ETCD_DATA_DIR="/var/lib/etcd/default"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
[root@localhost ~]# service etcd restart
[root@localhost ~]# netstat -antp | grep etcd //查看监听状态
[root@localhost ~]# ./apiserver.sh 192.168.16.132 http://192.168.16.132:2379 //启动api server
[root@localhost ~]# ps -ef|grep kube
[root@localhost ~]# journalctl -u kube-apiserver
[root@localhost ~]# ./scheduler.sh 192.168.16.132
[root@localhost ~]# journalctl -u kube-scheduler
[root@localhost ~]# ./controller-manager.sh 192.168.16.132
[root@localhost ~]# journalctl -u kube-controller-manager
[root@localhost ~]# netstat -antp | grep 8080
controller.go:128] Unable to perform initial IP allocation check: unable to refresh the service IP block: client: etcd
Mar 14 22:26:22 localhost.localdomain systemd[1]: kube-apiserver.service: main process exited, code=exited, status=255/n/a
Mar 14 22:26:22 localhost.localdomain systemd[1]: Unit kube-apiserver.service entered failed state.
Mar 14 22:26:22 localhost.localdomain systemd[1]: kube-apiserver.service failed.
Mar 14 22:26:22 localhost.localdomain systemd[1]: kube-apiserver.service holdoff time over, scheduling restart.
Mar 14 22:26:22 localhost.localdomain systemd[1]: Started Kubernetes API Server.
Mar 14 22:26:22 localhost.localdomain systemd[1]: Starting Kubernetes API Server...
1.6.2配置node节点
chmod +x *
[root@localhost ~]# mkdir -p /opt/kubernetes/{bin,cfg}
[root@localhost ~]# mv kubelet kube-proxy /opt/kubernetes/bin
[root@localhost ~]# ./kubelet.sh 192.168.16.132 192.168.16.133 10.10.10.2
[root@localhost ~]# journalctl -u kubelet
[root@localhost ~]# free -m
[root@localhost ~]# swapoff -a
[root@localhost ~]# systemctl start kubelet
[root@localhost ~]# netstat -antp | grep 10250
[root@localhost ~]# ./proxy.sh 192.168.16.132 192.168.16.133