添加工作节点

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

查看Token

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

加入集群

 kubeadm join 10.8.28.200: --token k60p22.go0fadibgqm2xcx8 \
--discovery-token-ca-cert-hash sha256:ffd76aed49c8f52dea15d16132897376176aea4c3ee50370e9369ca6c6c5a6b0 \
--node-name k8s-test-node-

以下为输出

[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节点

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

测试

测试pod

 # !!!待添加一个工作节点后运行
kubectl run nginx --image=nginx:1.14 --replicas=
## 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.
## deployment.apps/nginx created
kubectl get pods -o wide
## NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
## nginx-7b4d6c6559-4j78l / Running 22s 192.168.49.2 k8s-test-node- <none> <none>
## nginx-7b4d6c6559-nvlgg / Running 22s 192.168.49.1 k8s-test-node- <none> <none>
curl 192.168.49.2
...
<title>Welcome to nginx!</title>
...

测试dns

[root@k8s-test-master- ~]# 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 : 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: kubernetes.default
Address : 10.96.0.1 kubernetes.default.svc.cluster.local
04-25 17:36
查看更多