一、部署Kubernetes Master(在vip当前环境在节点上运行k8s-master2节点)
### --- 部署Kubernetes Master(在vip当前环境在节点上运行k8s-master2节点) [root@k8s-master2 ~]# ip a s ens34 3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.10.10.12/24 brd 10.10.10.255 scope global noprefixroute ens34 inet 10.10.10.15/32 scope global ens34
二、创建kubeadm配置文件
### --- 在具有vip的master上操作,这里为master2 [root@k8s-master2 ~]# mkdir /usr/local/kubernetes/manifests -p [root@k8s-master2 ~]# cd /usr/local/kubernetes/manifests/
[root@k8s-master2 manifests]# vi kubeadm-config.yaml apiServer: certSANs: - k8s-master1 # master1 - k8s-master2 # master2 - master.k8s.io # 定义自己的名字 - 10.10.10.15 # 虚拟IP地址 - 10.10.10.11 # k8s-master1节点IP地址 - 10.10.10.12 # k8s-master2节点IP地址 - 127.0.0.1 extraArgs: authorization-mode: Node,RBAC timeoutForControlPlane: 4m0s apiVersion: kubeadm.k8s.io/v1beta1 certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controlPlaneEndpoint: "master.k8s.io:16443" controllerManager: {} dns: type: CoreDNS etcd: local: dataDir: /var/lib/etcd imageRepository: registry.aliyuncs.com/google_containers kind: ClusterConfiguration kubernetesVersion: v1.16.3 networking: dnsDomain: cluster.local podSubnet: 10.244.0.0/16 serviceSubnet: 10.1.0.0/16 scheduler: {}
三、拉镜像
### --- 在master2节点执行拉取镜像(包括VIP节点执行) ~~~ 拉取镜像 [root@k8s-master2 manifests]# kubeadm init --config kubeadm-config.yaml [init] Using Kubernetes version: v1.16.3 Your Kubernetes control-plane has initialized successfully! # 提示kubectl初始化成功 To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube # 第一步:执行一些基本设置 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of control-plane nodes by copying certificate authorities # 第二步:需要添加其他节点 and service account keys on each node and then running the following as root: kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 \ --discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e \ --control-plane Then you can join any number of worker nodes by running the following on each as root: kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 \ --discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e
### --- 检查拉取的镜像 [root@k8s-master2 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.16.3 9b65a0f78b09 15 months ago 86.1MB registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.16.3 df60c7526a3d 15 months ago 217MB registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.16.3 bb16442bcd94 15 months ago 163MB registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.16.3 98fecf43a54f 15 months ago 87.3MB registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.3.15-0 b2756210eeab 17 months ago 247MB registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.2 bf261d157914 18 months ago 44.1MB registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 3 years ago 742kB
三、按提示执行部署kubernetes master
### --- 环境变量按提示配置,使用kubectl工具: ~~~ 第一步按提示执行 [root@k8s-master2 manifests]# mkdir -p $HOME/.kube [root@k8s-master2 manifests]# sudo cp -i /etc/kubrnetes/admin.conf $HOME/.kube/config
[root@k8s-master2 manifests]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
~~~ 查看集群状态
[root@k8s-master2 manifests]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master2 NotReady master 11m v1.16.3
### --- **按照提示保存以下内容,一会要使用:**
~~~ 后期在k8s-master执行
kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 \
--discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e \
--control-plane
~~~ 后期在k8s-node执行
kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 \
--discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e
### --- 查看集群状态
[root@k8s-master2 manifests]# kubectl get cs
NAME AGE
scheduler <unknown>
controller-manager <unknown>
etcd-0 <unknown>
[root@k8s-master2 manifests]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-67c766df46-n4vgq 0/1 Pending 0 9m24s
coredns-67c766df46-xlq2g 0/1 Pending 0 9m24s
etcd-k8s-master2 1/1 Running 0 8m20s
kube-apiserver-k8s-master2 1/1 Running 0 8m45s
kube-controller-manager-k8s-master2 1/1 Running 0 8m47s
kube-proxy-8tzb7 1/1 Running 0 9m24s
kube-scheduler-k8s-master2 1/1 Running 0 8m25s
附录一:拉取镜像失败
### --- 报错现象:
[root@k8s-master2 manifests]# kubeadm init --config kubeadm-config.yaml
[init] Using Kubernetes version: v1.16.3
[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/
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[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
### --- 解决方案:更换docker的daemon.json文件信息,可能源获取不到数据
[root@k8s-master1 ~]# tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
> "exec-opts": ["native.cgroupdriver=systemd"]
> }
> EOF
{
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}