k8s單master叢集部署
1. 伺服器要求:
1.1 軟體環境:
1.2 伺服器規劃:
1.3 架構圖:
2. 作業系統初始化配置
# 關閉防火牆 systemctl stop firewalld systemctl disable firewalld # 關閉selinux sed -i '/^SELINUX/s/enforcing/disabled/' /etc/selinux/config # 永久 setenforce 0 # 臨時 # 關閉swap swapoff -a # 臨時 sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久 # 根據規劃設定主機名 hostnamectl set-hostname <hostname> # 在master新增hosts cat >> /etc/hosts << EOF 192.168.137.81 k8s-master1 192.168.137.82 k8s-node1 192.168.137.83 k8s-node2 EOF # 將橋接的IPv4流量傳遞到iptables的鏈 cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system # 生效 # 時間同步 yum install ntpdate -y ntpdate time.windows.com
3. 安裝Docker/kubeadm/kubelet [所有節點]
3.1 安裝Docker
wget yum -y install docker-ce systemctl enable docker && systemctl start docker
3.2 配置映象下載加速器
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
3.3 新增阿里雲YUM軟體源
cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl= enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey= EOF
3.4 安裝kubeadm,kubelet,kubectl
yum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0 systemctl enable kubelet
4. 部署Kubernetes Master
kubeadm init \ --apiserver-advertise-address=192.168.137.81 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.20.0 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 \ --ignore-preflight-errors=all
# cat kubeadm.conf apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: v1.20.0 imageRepository: registry.aliyuncs.com/google_containers networking: podSubnet: 10.244.0.0/16 serviceSubnet: 10.96.0.0/12 # kubeadm init --config kubeadm.conf --ignore-preflight-errors=all
Your Kubernetes control-plane has initialized successfully! 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 Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: Then you can join any number of worker nodes by running the following on each as root: kubeadm join 192.168.137.81:6443 --token tix7ff.pnjcwvl6awyaeh8i \ --discovery-token-ca-cert-hash sha256:617842ea5040ce5e7f971d387b58693cbfa79261763b68c589fe8d124f1a5154
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@k8s-master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master1 NotReady control-plane,master 95s v1.20.0
5. 加入Kubernetes Node節點
kubeadm join 192.168.137.81:6443 --token tix7ff.pnjcwvl6awyaeh8i \ --discovery-token-ca-cert-hash sha256:617842ea5040ce5e7f971d387b58693cbfa79261763b68c589fe8d124f1a5154
kubeadm token create --print-join-command
6. 部署容器網路(CNI)
wget
kubectl apply -f calico.yaml kubectl get pods -n kube-system
[root@k8s-master <sub>]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE calico-kube-controllers-5f6cfd688c-4hfmv 1/1 Running 0 2m37s calico-node-8swrp 1/1 Running 0 2m37s calico-node-nv96p 1/1 Running 0 2m37s calico-node-s2vl6 1/1 Running 0 2m37s coredns-7f89b7bc75-7nzm8 0/1 Running 0 22m coredns-7f89b7bc75-9c46c 0/1 Running 0 22m etcd-k8s-master1 1/1 Running 0 22m kube-apiserver-k8s-master1 1/1 Running 0 22m kube-controller-manager-k8s-master1 1/1 Running 0 22m kube-proxy-clc6k 1/1 Running 0 18m kube-proxy-dvlvr 1/1 Running 0 22m kube-proxy-jr6hm 1/1 Running 0 18m kube-scheduler-k8s-master1 1/1 Running 0 22m [root@k8s-master </sub>]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master1 Ready control-plane,master 23m v1.20.0 k8s-node1 Ready <none> 18m v1.20.0 k8s-node2 Ready <none> 18m v1.20.0
7. 測試kubernetes叢集
kubectl create deployment nginx --image=nginx kubectl expose deployment nginx --port=80 --type=NodePort kubectl get pod,svc
[root@k8s-master ~]# kubectl get pod,svc NAME READY STATUS RESTARTS AGE pod/nginx-6799fc88d8-nkzk6 1/1 Running 0 6m51s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 32m service/nginx NodePort 10.108.121.252 <none> 80:30167/TCP 6m2s
8. 部署Dashboard
wget
# vi recommended.yaml ... kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: ports: - port: 443 targetPort: 8443 nodePort: 30001 selector: k8s-app: kubernetes-dashboard type: NodePort ... # kubectl apply -f recommended.yaml # kubectl get pods -n kubernetes-dashboard
# 建立使用者 $ kubectl create serviceaccount dashboard-admin -n kube-system # 使用者授權 $ kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin # 獲取使用者Token $ kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
[root@k8s-master ~]# kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}') Name: dashboard-admin-token-cgmld Namespace: kube-system Labels: <none> Annotations: kubernetes.io/service-account.name: dashboard-admin kubernetes.io/service-account.uid: 3208e176-5115-4425-bb67-d45863bc05f7 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1066 bytes namespace: 11 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6IlBnN2lzMk8zYndPX3ZONnc0cnFnRjhsVnczOTVlNGxXSDl4c1Z0OGtmNDAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tY2dtbGQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiMzIwOGUxNzYtNTExNS00NDI1LWJiNjctZDQ1ODYzYmMwNWY3Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.DY9SLeakUzVUqUHLJjLuaBtv0EOj6l-zsCfmzKTtsiTkaX39bGpLInToKuSpbXHYAmkpCvoZH22ghmOds3LFgvQBCIt6M83rrL83aPzhDjAKtPtPkz9vJGR7K5LnfrB9AX5dVhiU_AkaVIBIFcqTxVlFpl6W1EzTc0uJDM7K8Gr2XnPvRfUMe8WaEWR7tVxMEEhPhP2waEYmcc5uFz5unI_g6lTMYRJnhZCjfqh7lS9NA_8WgmoQnQjxW4cYAsqrdCzbroTEMCslH_pCj-PZNxf7mKVXZwklYL78t8klU_AytuhdaV88iRR3HEuBMYLbfJjy6RLkyt_ORweaXb8npg
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70003733/viewspace-2901591/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- K8S如何部署Redis(單機、叢集)K8SRedis
- 【K8S】基於單Master節點安裝K8S叢集K8SAST
- kubeadm部署K8S叢集K8S
- Ansible部署K8s叢集K8S
- 二進位制部署1.23.4版本k8s叢集-5-部署Master節點服務K8SAST
- k8s 部署生產vault叢集K8S
- 基於Ubuntu部署企業級kubernetes叢集---k8s叢集容部署UbuntuK8S
- [譯]單應用跨多k8s叢集的部署與管理K8S
- 升級kubeadm 叢集(只有master單節點)AST
- rocketMq叢集master模式搭建MQAST模式
- 通過kubeadm工具部署k8s叢集K8S
- 【k8s】使用Terraform一鍵部署EKS叢集K8SORM
- 基於kubeasz部署高可用k8s叢集K8S
- AnolisOS7.9部署K8s叢集K8S
- 升級 kubeadm 部署的 k8s 叢集K8S
- 簡單的方式搭建k8s叢集K8S
- 日誌分析系統 - k8s部署ElasticSearch叢集K8SElasticsearch
- 純手工搭建k8s叢集-(2)核心模組部署K8S
- Kubernetes(k8s)部署redis-cluster叢集K8SRedis
- Apache SeaTunnel k8s 叢集模式 Zeta 引擎部署指南ApacheK8S模式
- 排查 k8s 叢集 master 節點無法正常工作的問題K8SAST
- K8s 叢集高可用 master 節點故障如何恢復? 原創K8SAST
- 部署分片叢集
- linux搭建kafka叢集,多master節點叢集說明LinuxKafkaAST
- 【趙強老師】使用kubeadmin部署K8s叢集K8S
- k8s叢集部署K8S
- 使用kubeadm進行單master(single master)和高可用(HA)kubernetes叢集部署AST
- 使用Kubeadm建立k8s叢集之部署規劃(三十)K8S
- docker部署mysql叢集DockerMySql
- Docker部署ElasticSearch叢集DockerElasticsearch
- Kubernetes(k8s)叢集部署(k8s企業級Docker容器集K8SDocker
- kubeadm實現k8s高可用叢集環境部署與配置K8S
- 使用Kubeadm建立k8s叢集之節點部署(三十一)K8S
- 容器化 | 在 K8s 上部署 RadonDB MySQL Operator 和叢集K8SMySql
- k8s之叢集管理K8S
- 多k8s叢集管理K8S
- k8s 叢集升級K8S
- 刪除k8s叢集K8S