部署kubelet
在10.4.7.21和10.4.7.22主机上
一、签发证书(在harbor主机,10.4.7.200)
- 创建生成证书的json文件
cd /opt/certs/
vim kubelet-csr.json
{
"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": "ShangHai",
"L": "ShangHai",
"O": "xy",
"OU": "ops"
}
]
}
- 生成证书文件
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json | cfssl-json -bare kubelet
二、将证书拷贝至10.4.7.21和10.4.7.22主机,创建配置文件
1.拷贝证书(两台都)
cd /opt/kubernetes/server/bin/cert/
scp sx7-200:/opt/certs/kubelet.pem .
scp sx7-200:/opt/certs/kubelet-key.pem .
2.创建配置文件(在一台创建,最后拷贝到另一台即可)
cd /opt/kubernetes/server/bin/conf
<1>set-cluster
[root@sx7-21 conf]# kubectl config set-cluster myk8s
--certificate-authority=/opt/kubernetes/server/bin/cert/ca.pem
--embed-certs=true
--server=https://10.4.7.10:7443
--kubeconfig=kubelet.kubeconfig
<2>set-credentials
[root@sx7-21 conf]# kubectl config set-credentials k8s-node
--client-certificate=/opt/kubernetes/server/bin/cert/client.pem
--client-key=/opt/kubernetes/server/bin/cert/client-key.pem
--embed-certs=true
--kubeconfig=kubelet.kubeconfig
<3>set-context
[root@sx7-21 conf]# kubectl config set-context myk8s-context
--cluster=myk8s
--user=k8s-node
--kubeconfig=kubelet.kubeconfig
<4>use-context
[root@sx7-21 conf]# kubectl config use-context myk8s-context --kubeconfig=kubelet.kubeconfig
<5>k8s-node.yaml
vi k8s-node.yaml
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
b.应用资源配置
kubectl create -f k8s-node.yaml
c.查看集群角色和角色属性
kubectl get clusterrolebinding k8s-node
kubectl get clusterrolebinding k8s-node -o yaml
拷贝配置文件到10.4.7.22主机
[root@sx7-22 conf]# scp sx7-21:/opt/kubernetes/server/bin/conf/kubelet.kubeconfig .
三、准备pause镜像(在10.4.7.200主机)
1.下载镜像
docker pull kubernetes/pause
2.标记镜像
docker images | grep pause
docker tag f9d5de079539 harbor.xyly.com/public/pause:latest
3.上传到Harbor仓库
docker push harbor.xyly.com/public/pause:latest
查看仓库的镜像
四、启动kubelet服务(10.4.7.11,10.4.7.12主机)
1.创建启动脚本
vi /opt/kubernetes/server/bin/kubelet.sh //部署其他节点修改红色字体
#!/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 ./cert/ca.pem
--tls-cert-file ./cert/kubelet.pem
--tls-private-key-file ./cert/kubelet-key.pem
--hostname-override sx7-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.xyly.com/public/pause:latest // 修改为自己的harbor仓库地址
--root-dir /data/kubelet
修改脚本权限并创建目录
chmod +x /opt/kubernetes/server/bin/kubelet.sh
mkdir -p /data/logs/kubernetes/kube-kubelet /data/kubelet
2.创建supervisor配置
vim /etc/supervisord.d/kube-kubelet.ini // 另一台主机修改红色字体
[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)
启动服务
supervisorctl update
supervisorctl status
// 查看状态
3.检查节点情况,打标签
kubectl get nodes
给节点打标签
kubectl label node sx7-21.host.com node-role.kubernetes.io/master=
kubectl label node sx7-21.host.com node-role.kubernetes.io/node=
kubectl label node sx7-22.host.com node-role.kubernetes.io/master=
kubectl label node sx7-22.host.com node-role.kubernetes.io/node=