准备3台主节点:km1/km2/km3
1.编辑kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
networking:
serviceSubnet: 10.244.0.0/16
podSubnet: 10.68.0.0/16
kubernetesVersion: v1.13.2
controlPlaneEndpoint: kube.cluster:6443
apiServer:
certSANs:
- kube.cluster
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
ipvs:
minSyncPeriod: 1s
#rr-轮询 wrr-加权轮询 sh-地址哈希
scheduler: rr
syncPeriod: 10s
mode: ipvs
2. 编辑/etc/host
10.10.0.21 kube.cluster km1
10.10.0.21 kube.cluster km2
10.10.0.21 kube.cluster km3
3. 初始化机器
#初始化命令
kubeadm init --config /root/kubeadm-config-success.yaml
#给kubectl工具授权
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config ####加入命令会在初始化后显示
kubeadm join kube.cluster:6443 --token ovulns.p5k9x8tfpktkcbyy --discovery-token-ca-cert-hash \
sha256:4559cb9fe37f9ba2c8cc3ab1e633d7bb46815bcd14adfceaa020d47d9b4d13d6
4. 将km1生产的密匙上传到km2、km3
##使用脚本传钥匙
#!/bin/bash
i=$1
ssh $i "mkdir -p /etc/kubernetes/pki/etcd; mkdir -p ~/.kube/"
scp /etc/kubernetes/pki/ca.crt $i:/etc/kubernetes/pki/ca.crt
scp /etc/kubernetes/pki/ca.key $i:/etc/kubernetes/pki/ca.key
scp /etc/kubernetes/pki/sa.key $i:/etc/kubernetes/pki/sa.key
scp /etc/kubernetes/pki/sa.pub $i:/etc/kubernetes/pki/sa.pub
scp /etc/kubernetes/pki/front-proxy-ca.crt $i:/etc/kubernetes/pki/front-proxy-ca.crt
scp /etc/kubernetes/pki/front-proxy-ca.key $i:/etc/kubernetes/pki/front-proxy-ca.key
scp /etc/kubernetes/pki/etcd/ca.crt $i:/etc/kubernetes/pki/etcd/ca.crt
scp /etc/kubernetes/pki/etcd/ca.key $i:/etc/kubernetes/pki/etcd/ca.key
scp /etc/kubernetes/admin.conf $i:/etc/kubernetes/admin.conf
scp /etc/kubernetes/admin.conf $i:~/.kube/config
5. 将km2/km3加入到集群中
kubeadm join kube.cluster:6443 --token ovulns.p5k9x8tfpktkcbyy --discovery-token-ca-cert-hash \
sha256:4559cb9fe37f9ba2c8cc3ab1e633d7bb46815bcd14adfceaa020d47d9b4d13d6 \
--experimental-control-plane #需要加入此参数