Kubernetes node 上的组件安装配置

1.简介

kubernetes 的node节点上安装的组件主要包括;kubelet,kube-proxy

2.拷贝文件到node节点中,进入kubernetes的解压目录的/kubernetes/server/bin

将安装包下的kubelet和kube-proxy两个可执行文件拷贝到node的安装目录下

[root@dn01 bin]# pwd
/root/k8s/kubernetes/server/bin
[root@dn01 bin]# scp kubelet kube-proxy root@10.10.100.31:/opt/kubernetes/bin
root@10.10.100.31's password: 
kubelet                                                                               100%  169MB  34.1MB/s   00:04    
kube-proxy                                                                            100%   48MB  26.9MB/s   00:01    
[root@dn01 bin]# scp kubelet kube-proxy root@10.10.100.32:/opt/kubernetes/bin
root@10.10.100.32's password: 
kubelet                                                                               100%  169MB  28.1MB/s   00:06    
kube-proxy                                                                            100%   48MB  20.6MB/s   00:02    
View Code

3.安装配置

3.1在master 生成kubelet.kubeconfig和bootstrap.kubeconfig文件

为生成文件创建文件夹,方便存储和查找

[root@dn01 k8s]# mkdir kubeconfig

生成bootstrap.kubeconfig

设置集群参数

kubectl config set-cluster kubernetes \
--certificate-authority=/root/k8s/k8s-cert/ca.pem \
--embed-certs=true \
--server="https://10.10.100.30:6443" \
--kubeconfig=bootstrap.kubeconfig
View Code

设置客户端认证参数

kubectl config set-credentials kubelet-bootstrap \
--token=0fb61c46f8991b718eb38d27b605b008 \ 
--kubeconfig=bootstrap.kubeconfig

注意:token 的id对应的文件
[root@dn01 kubeconfig]# cat /opt/kubernetes/cfg/token.csv 
0fb61c46f8991b718eb38d27b605b008,kubelet-bootstrap,10001,"system:kubelet-bootstrap"
[root@dn01 kubeconfig]# 
View Code

设置上下文参数

kubectl config set-context default \
  --cluster=kubernetes \
  --user=kubelet-bootstrap \
  --kubeconfig=bootstrap.kubeconfig
View Code

设置默认上下文

kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
View Code

最终生成的文件内容:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR2akNDQXFh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EVCQU1DQVFZd0VnWURWUjBUQVFIL0JBZ3dCZ0VCL3dJQkFqQWQKQmdOVkhRNEVGZ1FVUmhhU2dDakF3VmZoZmswblhLM3hHQ2cvWnZZd0h3WURWUjBqQkJnd0ZvQVVSaGFTZ0NqQQp3VmZoZmswblhLM3hHQ2cvWnZZd0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFCVHlNM2xPdUNOS2FDcTBYc01iClExTkptWCtIUTVxa1lSeURQMHJHSjZDL2w0RzJwNnc3bTBvc1FLdTdUSUxSWmZ1OFBLU1B2SDlmejdaYlg4YnYKVzQ3RzZOSlNPODdxaExLVU9rMHdCNElvUDcyZndBeU92Y2NnWHZrSUU5Rk9wekZYZ2p0dUcvL0M4MFJNTjA0bApHa1R6Y2RFaGZQUDBoT2I0OXdrcnRKa2c4c1M2bDRXaUN0eDB5amNMK2NkM1VRSGRkSGZCc04ydlpyWXpQZGJqCllBRjFOMU4wa0RBUy90N0d3S29XSUdzR0pPQTVJUDdSMHdtb3dWZVBJZ2xrQWZWcTV6NVRwalZ2ZjBXUC9RbnEKd1VCcm1uV3hSRGxCUHJBeEEzY3Rnb2MrZ042WFAvNURRU2pRT0V0QjBMb09GUUJiTGo2dGpLODlHZnJ1NzVENgpBaWM9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://10.10.100.30:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubelet-bootstrap
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: kubelet-bootstrap
  user:
    token: 0fb61c46f8991b718eb38d27b605b008
View Code

生成 kube-proxy.kubeconfig文件

设置集群参数

kubectl config set-cluster kubernetes \
  --certificate-authority=/root/k8s/k8s-cert/ca.pem \
  --embed-certs=true \
  --server="https://10.10.100.30:6443" \
  --kubeconfig=kube-proxy.kubeconfig
View Code

设置客户端认证参数

kubectl config set-credentials kube-proxy \
--client-certificate=/root/k8s/k8s-cert/kube-proxy.pem \
--client-key=/root/k8s/k8s-cert/kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=kube-proxy.kubeconfig
View Code

设置上下文参数

kubectl config set-context default \
  --cluster=kubernetes \
  --user=kube-proxy \
  --kubeconfig=kube-proxy.kubeconfig
View Code

设置默认上下文

kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
View Code

最终生成的文件内容:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR2akNDQXFhZ0F3SUJBZ0lVWkZwS1RpOEhCbDZVR0Vsd0M3UzgvM3Jic1FNd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1pURUxNQWtHQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFXcHBibWN4RURBT0JnTlZCQWNUQjBKbAphV3BwYm1jeEREQUtCZ05WQkFvVEEyczRjekVQTUEwR0ExVUVDeE1HVTNsemRHVnRNUk13RVFZRFZRUURFd3ByCmRXSmxjbTVsZEdWek1CNFhEVEU1TURreE5URTBORGd3TUZvWERUSTBNRGt4TXpFME5EZ3dNRm93WlRFTE1Ba0cKQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFXcHBibWN4RURBT0JnTlZCQWNUQjBKbGFXcHBibWN4RERBSwpCZ05WQkFvVEEyczRjekVQTUEwR0ExVUVDeE1HVTNsemRHVnRNUk13RVFZRFZRUURFd3ByZFdKbGNtNWxkR1Z6Ck1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBbFJTWWlRY0lQZVo1cjN2RUZrekEKUFhFRHlWT0daVVZCcEFrTzlDK1N6b0k0VWVHckQ4aU5sYmNBU0c1OW5uenhlNmNjSFYvMkhkelRyMFc5U0pmVgpkNTBiNTRwWnovYjhPMll4YVNPNWljWWZmcmRpTThLNDJxM3FnMmc5VCtIKzkvQ3VzY3R4N1ZHL1N1Z1lIdmxyCmJYMHdrK3VCbEsrRkFseHVaOVNOUzIyQ3dGQllXRHkvakQvMkpLa2oySGhjMXFHNGpMRGwvRnVDZXhGRnZFTmoKbWlzV00rdVgwQkxqcHJ2Rll1N0RrZjRwV1N4UXUyQ3NEcGZ2NTJjQTdLdDdYakt0RW13SkEyeURZUi9uME1TOQpqSDFaZ3F6eTRHWW1zYlZ3cXIzeUE5WkIwYzY1SklLOHQxK3pxSG5CcHlsbmpBM3JvenNIYkxlVGM5YmVud3kyCnpRSURBUUFCbzJZd1pEQU9CZ05WSFE4QkFmOEVCQU1DQVFZd0VnWURWUjBUQVFIL0JBZ3dCZ0VCL3dJQkFqQWQKQmdOVkhRNEVGZ1FVUmhhU2dDakF3VmZoZmswblhLM3hHQ2cvWnZZd0h3WURWUjBqQkJnd0ZvQVVSaGFTZ0NqQQp3VmZoZmswblhLM3hHQ2cvWnZZd0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFCVHlNM2xPdUNOS2FDcTBYc01iClExTkptWCtIUTVxa1lSeURQMHJHSjZDL2w0RzJwNnc3bTBvc1FLdTdUSUxSWmZ1OFBLU1B2SDlmejdaYlg4YnYKVzQ3RzZOSlNPODdxaExLVU9rMHdCNElvUDcyZndBeU92Y2NnWHZrSUU5Rk9wekZYZ2p0dUcvL0M4MFJNTjA0bApHa1R6Y2RFaGZQUDBoT2I0OXdrcnRKa2c4c1M2bDRXaUN0eDB5amNMK2NkM1VRSGRkSGZCc04ydlpyWXpQZGJqCllBRjFOMU4wa0RBUy90N0d3S29XSUdzR0pPQTVJUDdSMHdtb3dWZVBJZ2xrQWZWcTV6NVRwalZ2ZjBXUC9RbnEKd1VCcm1uV3hSRGxCUHJBeEEzY3Rnb2MrZ042WFAvNURRU2pRT0V0QjBMb09GUUJiTGo2dGpLODlHZnJ1NzVENgpBaWM9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://10.10.100.30:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kube-proxy
  name: default
current-context: default
kind: Config
preferences: {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定系统集群角色(在master上执行)

[root@dn01 kubeconfig]# kubectl create clusterrolebinding kubelet-bootstrap \
> --clusterrole=system:node-bootstrapper \
> --user=kubelet-bootstrap

执行结果
clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created
View Code

3.3生成node节点的kubelet配置文件

cat <<EOF >/opt/kubernetes/cfg/kubelet

KUBELET_OPTS="--logtostderr=true \\
--v=4 \\
--hostname-override=10.10.100.31 \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--config=/opt/kubernetes/cfg/kubelet.config \\
--cert-dir=/opt/kubernetes/ssl \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"

EOF
View Code
cat <<EOF >/opt/kubernetes/cfg/kubelet.config

kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 10.10.100.31
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2 
clusterDomain: cluster.local.
failSwapOn: false
authentication:
  anonymous:
    enabled: true
EOF
View Code

为kubelet配置system 的服务

cat <<EOF >/usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service

[Service]
EnvironmentFile=/opt/kubernetes/cfg/kubelet
ExecStart=/opt/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
KillMode=process

[Install]
WantedBy=multi-user.target
EOF
View Code

 启动kubelet服务

重新加载服务文件
[root@dn02 ~]# systemctl daemon-reload
设置开机启动
[root@dn02 ~]# systemctl enable kubelet
启动服务
[root@dn02 ~]# systemctl restart kubelet
View Code

此时在master 节点上通过命令可以看到一个节点正在等待为它颁发证书,颁发证书之后node节点就会加入集群

[root@dn01 kubeconfig]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc 12m kubelet-bootstrap Pending
View Code

3.4 在master上为节点1授权证书

[root@dn01 kubeconfig]# kubectl certificate approve node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc
certificatesigningrequest.certificates.k8s.io/node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc approved
[root@dn01 kubeconfig]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc 16m kubelet-bootstrap Approved,Issued
View Code

此时集群中就会看到一个节点

[root@dn01 kubeconfig]# kubectl get node
NAME STATUS ROLES AGE VERSION
10.10.100.31 Ready <none> 96s v1.12.10
View Code

3.5 node部署proxy

为porxy设置配置文件

cat <<EOF >/opt/kubernetes/cfg/kube-proxy

KUBE_PROXY_OPTS="--logtostderr=true \\
--v=4 \\
--hostname-override=10.10.100.31 \\  ##节点1的地址
--cluster-cidr=10.0.0.0/24 \\
--proxy-mode=ipvs \\
--masquerade-all=true \\
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"

EOF
View Code

为proxy 配置system服务文件

cat <<EOF >/usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Proxy
After=network.target

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-proxy
ExecStart=/opt/kubernetes/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
View Code

启动kube-proxy服务

重新加服务配置文件
[root@dn02 ~]# systemctl daemon-reload
设置开机启动
[root@dn02 ~]# systemctl enable kube-proxy
启动服务
[root@dn02 ~]# systemctl restart kube-proxy
View Code

检查kubelet和kube-proxy服务装填

[root@dn02 ~]# ps -ef | grep kubelet
root      15203      1  1 20:01 ?        00:00:31 /opt/kubernetes/bin/kubelet --logtostderr=true --v=4 --hostname-override=10.10.100.31 --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig --bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig --config=/opt/kubernetes/cfg/kubelet.config --cert-dir=/opt/kubernetes/ssl --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
root      20798   7335  0 20:31 pts/0    00:00:00 grep --color=auto kubelet

[root@dn02 ~]# ps -ef | grep kube-proxy
root      17922      1  0 20:23 ?        00:00:03 /opt/kubernetes/bin/kube-proxy --logtostderr=true --v=4 --hostname-override=10.10.100.31 --cluster-cidr=10.0.0.0/24 --proxy-mode=ipvs --kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig
root      20854   7335  0 20:31 pts/0    00:00:00 grep --color=auto kube-proxy
[root@dn02 ~]# 
View Code

此时,完成对第一个节点加入kubenetes集群的配置

4. 增加第二个节点

4.1在部署第二个node节点时可以直接将部署好的节点的配置文件直接拷贝到新的节点上

拷贝部署的目录文件

[root@dn02 ~]# scp -r /opt/kubernetes/ root@10.10.100.32:/opt/
root@10.10.100.32's password: 
flanneld                                                                                             100%  232    74.4KB/s   00:00    
bootstrap.kubeconfig                                                                                 100% 2166    49.6KB/s   00:00    
kube-proxy.kubeconfig                                                                                100% 6272   885.9KB/s   00:00    
kubelet                                                                                              100%  376    81.3KB/s   00:00    
kubelet.config                                                                                       100%  266    98.3KB/s   00:00    
kubelet.kubeconfig                                                                                   100% 2295   120.5KB/s   00:00    
kube-proxy                                                                                           100%  188   147.7KB/s   00:00    
mk-docker-opts.sh                                                                                    100% 2139     3.1MB/s   00:00    
scp: /opt//kubernetes/bin/flanneld: Text file busy
kubelet                                                                                              100%  169MB  94.0MB/s   00:01    
kube-proxy                                                                                           100%   48MB  75.5MB/s   00:00    
kubelet.crt                                                                                          100% 2181   121.6KB/s   00:00    
kubelet.key                                                                                          100% 1679     1.3MB/s   00:00    
kubelet-client-2019-09-21-20-18-08.pem                                                               100% 1273   659.9KB/s   00:00    
kubelet-client-current.pem 
View Code

拷贝system 的服务配置文件

[root@dn02 ~]# scp  /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@10.10.100.32:/usr/lib/systemd/system
root@10.10.100.32's password: 
kubelet.service                                                                                      100%  264   126.8KB/s   00:00    
kube-proxy.service                                                                                   100%  231   247.8KB/s   00:00 
View Code

拷贝完成之后,需要注意,需要将/opt/kubernetes/ssl证书目录下的文件全部删除,因为这部书证书是由master颁发给node节点的,新节点需要重新

让maser 节点为该node 节点授权证书。

[root@dn03 ssl]# ls
kubelet-client-2019-09-21-20-18-08.pem  kubelet-client-current.pem  kubelet.crt  kubelet.key
[root@dn03 ssl]# rm -rf ./*
[root@dn03 ssl]# ls
[root@dn03 ssl]# 
View Code

4.2修改拷贝到新节点的配置文件,将涉及ip的配置文件的ip修改为本地ip

修改的配置文件在目录/opt/kubernetes/cfg

修改kubelet文件

[root@dn03 cfg]# vi kubelet


KUBELET_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=10.10.100.32 \ ###修改为本节点的ip
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \
--config=/opt/kubernetes/cfg/kubelet.config \
--cert-dir=/opt/kubernetes/ssl \
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
View Code

修改kubelet.config文件

[root@dn03 cfg]# vi kubelet.config 


kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 10.10.100.32 ###修改为本节点ip
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local.
failSwapOn: false
authentication:
  anonymous:
    enabled: true
View Code

修改kube-proxy文件

[root@dn03 cfg]# vi kube-proxy


KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=10.10.100.32 \ ###修改为本节点ip
--cluster-cidr=10.0.0.0/24 \
--proxy-mode=ipvs \
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
View Code

文件修改完后,可以直接启动

启动kubelet

[root@dn03 cfg]# systemctl start kubelet

[root@dn03 cfg]# ps -ef | grep kubelet
root       9741      1  3 22:30 ?        00:00:00 /opt/kubernetes/bin/kubelet --logtostderr=true --v=4 --hostname-override=10.10.100.32 --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig --bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig --config=/opt/kubernetes/cfg/kubelet.config --cert-dir=/opt/kubernetes/ssl --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
root       9766   7325  0 22:30 pts/0    00:00:00 grep --color=auto kubelet
View Code

启动kube-proxy

[root@dn03 cfg]# systemctl start kube-proxy

[root@dn03 cfg]# ps -ef | grep kube-proxy
root       9803      1  2 22:31 ?        00:00:00 /opt/kubernetes/bin/kube-proxy --logtostderr=true --v=4 --hostname-override=10.10.100.32 --cluster-cidr=10.0.0.0/24 --proxy-mode=ipvs --kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig
root       9979   7325  0 22:31 pts/0    00:00:00 grep --color=auto kube-proxy
View Code

4.3 到master上查看节点情况,执行kubectl get csr

[root@dn01 ~]# kubectl get csr
NAME                                                   AGE     REQUESTOR           CONDITION
node-csr-1t6R1ULc0q7W2ikLR8FaIL3wr91gUTVNMKm5nOatj1c   2m43s   kubelet-bootstrap   Pending
node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc   151m    kubelet-bootstrap   Approved,Issued
View Code

这时发现又多了一个等待授权的节点

4.4 执行3.4的命令为新节点授权,颁发证书

执行授权:kubectl certificate approve 节点名称

新节点等待颁发证书授权
[root@dn01 ~]# kubectl get csr
NAME                                                   AGE     REQUESTOR           CONDITION
node-csr-1t6R1ULc0q7W2ikLR8FaIL3wr91gUTVNMKm5nOatj1c   2m43s   kubelet-bootstrap   Pending
node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc   151m    kubelet-bootstrap   Approved,Issued

执行下发证书,授权
[root@dn01 ~]# kubectl certificate approve node-csr-1t6R1ULc0q7W2ikLR8FaIL3wr91gUTVNMKm5nOatj1c
certificatesigningrequest.certificates.k8s.io/node-csr-1t6R1ULc0q7W2ikLR8FaIL3wr91gUTVNMKm5nOatj1c approved

执行结果
[root@dn01 ~]# kubectl get csr
NAME                                                   AGE     REQUESTOR           CONDITION
node-csr-1t6R1ULc0q7W2ikLR8FaIL3wr91gUTVNMKm5nOatj1c   6m35s   kubelet-bootstrap   Approved,Issued
node-csr-OajWzrmC3Jvalvk1tBHClEEadSPM34bU7D1zvdQVJRc   155m    kubelet-bootstrap   Approved,Issued

新节点已经被添加
View Code

经过授权的节点已经成功加入集群

[root@dn01 ~]# kubectl get node
NAME           STATUS   ROLES    AGE     VERSION
10.10.100.31   Ready    <none>   142m    v1.12.10
10.10.100.32   Ready    <none>   3m38s   v1.12.10
View Code

此时即可完成单master加俩个node节点的kubernetes的集群搭建

 

posted @ 2019-09-21 14:45  彦祚  阅读(607)  评论(0编辑  收藏  举报