1.首先在新节点的机器上配置好master节点的host
编辑/etc/host 文件添加master 节点的域名IP192.168.30.131 apiserver.cluster.local
2.在master节点上执行 kubeadm token create --print-join-command
执行上面命令后将会输出root@node1:~# kubeadm token create --print-join-command
kubeadm join apiserver.cluster.local:6443 --token 0nptjy.lvbyzgl0v8v7yl2l --discovery-token-ca-cert-hash sha256:31bea31503ae327e2c416aa310b61601fd6ae81c3ca31eaaf5c2f491f4d103cc
3.接着在新节点机器上执行 master节点上面命令输出结果➜ ~ kubeadm join apiserver.cluster.local:6443 --token 0nptjy.lvbyzgl0v8v7yl2l --discovery-token-ca-cert-hash sha256:31bea31503ae327e2c416aa310b61601fd6ae81c3ca31eaaf5c2f491f4d103cc
W1221 00:02:47.329071 15355 join.go:368] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
This is not a control plan
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR IsPrivilegedUser]: user is not running as root
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
➜ ~ sudo kubeadm join apiserver.cluster.local:6443 --token 0nptjy.lvbyzgl0v8v7yl2l --discovery-token-ca-cert-hash sha256:31bea31503ae327e2c416aa310b61601fd6ae81c3ca31eaaf5c2f491f4d103cc
W1221 00:03:13.463931 15552 join.go:368] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
This is not a control plan
[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/
[WARNING FileExisting-ebtables]: ebtables not found in system path
[WARNING FileExisting-ethtool]: ethtool not found in system path
[WARNING FileExisting-socat]: socat not found in system path
[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.17" 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] Starting the kubelet
[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.
在master节点上查看添加结果root@node1:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready master 4d1h v1.17.0
node2 Ready 4d1h v1.17.0
xytschool Ready 4m11s v1.17.0
查看master节点信息root@node1:~# kubectl -n kube-system get cm kubeadm-config -oyaml
apiVersion: v1
data:
ClusterConfiguration: |
apiServer:
certSANs:
- 127.0.0.1
- apiserver.cluster.local
- 192.168.30.131
- 10.103.97.2
extraArgs:
authorization-mode: Node,RBAC
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: apiserver.cluster.local:6443
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.17.0
networking:
dnsDomain: cluster.local
podSubnet: 100.64.0.0/10
serviceSubnet: 10.96.0.0/12
scheduler: {}
ClusterStatus: |
apiEndpoints:
node1:
advertiseAddress: 192.168.30.131
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterStatus
kind: ConfigMap
metadata:
creationTimestamp: "2019-12-16T14:50:46Z"
name: kubeadm-config
namespace: kube-system
resourceVersion: "152"
selfLink: /api/v1/namespaces/kube-system/configmaps/kubeadm-config
uid: 038ce30d-8f9e-49bb-90e6-317c46f59d7e