上一章:二进制部署K8s集群第10节Master节点之部署四层反向代理
架构图
目录
1、架构
2、创建生成kubelet服务端证书csr的json配置文件
3、生成拷贝kubelet证书文件
4、下载pause镜像打tab
5、创建kubeconfig配置
6、拷贝配置
7、创建资源配置文件
8、应用查看资源配置
9、创建kubelet启动脚本
10、创建supervisor配置
11、启动检查打标签
1、架构
2、创建生成kubelet服务端证书csr的json配置文件
在hdss7-200.host.com上操作
cd /opt/certs/
cat > kubelet-csr.json <<eof
{
"CN": "k8s-kubelet",
"hosts": [
"127.0.0.1",
"10.4.7.10",
"10.4.7.21",
"10.4.7.22",
"10.4.7.23",
"10.4.7.24",
"10.4.7.25",
"10.4.7.26",
"10.4.7.27",
"10.4.7.28"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "beijing",
"L": "beijing",
"O": "od",
"OU": "ops"
}
]
}
eof
3、生成拷贝kubelet证书文件
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json | cfssl-json -bare kubelet
ll kubelet*
-rw-r--r--. 1 root root 1115 9月 20 19:24 kubelet.csr
-rw-r--r--. 1 root root 452 9月 20 19:24 kubelet-csr.json
-rw-------. 1 root root 1675 9月 20 19:24 kubelet-key.pem
-rw-r--r--. 1 root root 1472 9月 20 19:24 kubelet.pem
scp kubelet-key.pem kubelet.pem hdss7-21:/opt/kubernetes/server/bin/certs/
scp kubelet-key.pem kubelet.pem hdss7-22:/opt/kubernetes/server/bin/certs/
4、下载pause镜像打tab
kubelet利用pause镜像给容器建UTS\NET\IPC
docker pull kubernetes/pause
docker images | grep pause
kubernetes/pause latest f9d5de079539 6 years ago 240kB
docker tag f9d5de079539 harbor.od.com/public/pause:latest
docker login harbor.od.com # 用户名admin,密码Harbor12345
docker push harbor.od.com/public/pause:latest
5、创建kubeconfig配置
在hdss7-21.host.com上操作
5.1 set-cluster
cd /opt/kubernetes/server/bin/conf
kubectl config set-cluster myk8s \
--certificate-authority=/opt/kubernetes/server/bin/certs/ca.pem \
--embed-certs=true \
--server=https://10.4.7.10:7443 \
--kubeconfig=kubelet.kubeconfig
5.2 set-credentials
kubectl config set-credentials k8s-node \
--client-certificate=/opt/kubernetes/server/bin/certs/client.pem \
--client-key=/opt/kubernetes/server/bin/certs/client-key.pem \
--embed-certs=true \
--kubeconfig=kubelet.kubeconfig
5.3 set-context
kubectl config set-context myk8s-context \
--cluster=myk8s \
--user=k8s-node \
--kubeconfig=kubelet.kubeconfig
5.4 use-context
kubectl config use-context myk8s-context --kubeconfig=kubelet.kubeconfig
ll
总用量 12
-rw-r--r--. 1 root root 2223 9月 20 03:01 audit.yaml
-rw-------. 1 root root 6231 9月 20 19:51 kubelet.kubeconfig
6、拷贝配置scp kubelet.kubeconfig hdss7-22:/opt/kubernetes/server/bin/conf/
7、创建资源配置文件
cat > k8s-node.yaml <<eof
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: k8s-node
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:node
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: k8s-node
eof
8、应用查看资源配置
kubectl create -f k8s-node.yaml
kubectl get clusterrolebinding k8s-node
kubectl get clusterrolebinding k8s-node -o yaml
应用资源配置则会上传数据到etcd
9、创建kubelet启动脚本
以hdss7-21操作为例,hdss7-22操作类似
配置不同地方 --hostname-override
cat > /opt/kubernetes/server/bin/kubelet.sh <<eof
#!/bin/sh
./kubelet \
--anonymous-auth=false \
--cgroup-driver systemd \
--cluster-dns 192.168.0.2 \
--cluster-domain cluster.local \
--runtime-cgroups=/systemd/system.slice \
--kubelet-cgroups=/systemd/system.slice \
--fail-swap-on="false" \
--client-ca-file ./certs/ca.pem \
--tls-cert-file ./certs/kubelet.pem \
--tls-private-key-file ./certs/kubelet-key.pem \
--hostname-override hdss7-21.host.com \
--image-gc-high-threshold 20 \
--image-gc-low-threshold 10 \
--kubeconfig ./conf/kubelet.kubeconfig \
--log-dir /data/logs/kubernetes/kube-kubelet \
--pod-infra-container-image harbor.od.com/public/pause:latest \
--root-dir /data/kubelet
eof
chmod +x /opt/kubernetes/server/bin/kubelet.sh
mkdir -p /data/logs/kubernetes/kube-kubelet /data/kubelet
10、创建supervisor配置
cat > /etc/supervisord.d/kube-kubelet.ini <<eof
[program:kube-kubelet-7-21]
command=/opt/kubernetes/server/bin/kubelet.sh ; the program (relative uses PATH, can take args)
numprocs=1 ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=30 ; number of secs prog must stay running (def. 1)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
user=root ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-kubelet/kubelet.stdout.log ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
eof
配置不同地方 [program:kube-kubelet-7-21]
11、启动检查打标签
supervisorctl update
supervisorctl status
kubectl get nodes
kubectl label node hdss7-22.host.com node-role.kubernetes.io/node=
kubectl label node hdss7-21.host.com node-role.kubernetes.io/node=
kubectl label node hdss7-21.host.com node-role.kubernetes.io/master=
kubectl label node hdss7-22.host.com node-role.kubernetes.io/master=
kubectl get nodes
来源:oschina
链接:https://my.oschina.net/u/4343285/blog/4658997