|NO.Z.00030|——————————|^^ 部署 ^^|——|Kubernetes&高可用叢集.V04|------------------------------------|Kubernetes Master|
阿新 • • 發佈:2022-03-28
[CloudNative:Kubernetes&高可用叢集.V04] [Applications.CloudNative] [|雲端計算|K8S|叢集搭建-高可用叢集-實現過程介紹/初始化和部署Keepalived/] [部署haproxy和docker等元件/部署master1節點初始化/部署master2和node節點|]
一、部署Kubernetes Master(在vip所在節點上進行操作,當前環境在k8s-master2節點)
二、建立kubeadm配置檔案### --- 部署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
### --- 在具有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/kubernetes/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"]
}
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)