kubeadm安装集群系列-3.添加工作节点

添加工作节点

worker通过kubeadm join加入集群,加入所需的集群的token默认24小时过期

查看Token

1 kubeadm token list
2 # 如果失效创建一个新的
3 kubeadm create token
4 # 获取ca证书sha256编码hash值
5 openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
6 ## ffd76aed49c8f52dea15d16132897376176aea4c3ee50370e9369ca6c6c5a6b0

加入集群

1 kubeadm join 10.8.28.200:6443 --token k60p22.go0fadibgqm2xcx8 
2     --discovery-token-ca-cert-hash sha256:ffd76aed49c8f52dea15d16132897376176aea4c3ee50370e9369ca6c6c5a6b0 
3     --node-name k8s-test-node-1

以下为输出

[preflight] Running pre-flight checks
    [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.15" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

检查node节点

1 [root@k8s-test-master-1 .kube]# kubectl get nodes
2 NAME                STATUS   ROLES    AGE     VERSION
3 k8s-test-master-1   Ready    master   146m    v1.15.1
4 k8s-test-master-2   Ready    master   121m    v1.15.1
5 k8s-test-master-3   Ready    master   116m    v1.15.1
6 k8s-test-node-1     Ready    <none>   3m47s   v1.15.1

测试

测试pod

 1 # !!!待添加一个工作节点后运行
 2 kubectl run nginx --image=nginx:1.14 --replicas=2
 3 ## kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
 4 ## deployment.apps/nginx created
 5 kubectl get pods -o wide
 6 ## NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE              NOMINATED NODE   READINESS GATES
 7 ## nginx-7b4d6c6559-4j78l   1/1     Running   0          22s   192.168.49.2   k8s-test-node-1   <none>           <none>
 8 ## nginx-7b4d6c6559-nvlgg   1/1     Running   0          22s   192.168.49.1   k8s-test-node-1   <none>           <none>
 9 curl 192.168.49.2
10 ...
11 <title>Welcome to nginx!</title>
12 ...

测试dns

[root@k8s-test-master-1 ~]# kubectl run curl --image=radial/busyboxplus:curl -it
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
If you don't see a command prompt, try pressing enter.
[ root@curl-6bf6db5c4f-d5lv9:/ ]$ nslookup kubernetes.default
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
原文地址:https://www.cnblogs.com/dolphintwo/p/11310874.html