linux服务器连接k8s平台配置
linux服务器连接k8s平台配置
·
前言
为避免直接在k8s的master上进行kubectl等相关行为的操作,而导致误操作k8s上master的故障,现进行在其它服务器上的操作配置
连接配置
请自行准备1台linux服务器
安装kubectl工具
]# cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
]# sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes ; sudo systemctl enable --now kubelet ; echo 'source <(kubectl completion bash)' >>~/.bashrc ; echo 'source <(kubeadm completion bash)' >>~/.bashrc
配置连接
- config配置文件从k8s的master的节点下的/root/.kube/config获取,并在linux服务器上修改为k8s的master节点的IP
]# mkdir -p /root/.kube
]# cd /root/.kube
]# cat > config <<-EOF
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1EUXhNVEV5TWpVd05Gb1hEVE15TURRd09ERXlNalV3TkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTWJkCksxQmtCWVdjZFJtWmtwRnZkejR0WWh0RU1XZnZIbWdFTDdIYTBwZEltQlVickpBVE1ZakVtbWVlY1B1SWpUaWcKbk5rRlhqdUZkcTJCeEU3NDYxTGY4cUc5RVhTNTNGckp3TG95azZHUnpRWjVuajlTeUFERjhMK1BmcEVyOVJqSwpYMnZ2akV5NzI4OUV5a0hVS01YK0dxNTFHWVppc2tHNGpDQ2FRcTZvcC9MSXBENE1HTGFtOVROMTJ1aHNOVDBSCjdHbi82U2srOXd1TTBtbUxTNWN5cmhMaisydzNxRzZzQ2w0ZFU3Smp5RHBXRWwwaERVSkJlRnh3d2NhdVlLamEKQ3pqSkwxWkFPWERuN05VZU9uZHVMZHR4MTBDcGZGTmlUMEpMQnhDSWVYZVdSbmtlNytCZG9TTTNwM2lrOExpdwozZWRLZ0lIQXd4ZjJEd2FBUzBVQ0F3RUFBYU5DTUVBd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZDRk1qS1Y2M1JkelN0N0ZiUWdnWG1TckZFdzhNQTBHQ1NxR1NJYjMKRFFFQkN3VUFBNElCQVFCTGZwYytMVy82NnIxS00wZFlaaU9CeTZoVm5TZ2RhbjJJakxnRUVFekJMTFV4b3VQTApCd2NVMzdnaDRWQTV2L0R0aEhadU9IbjlMN3FjTDJEOVAxbzc2c1c4VHJXTk13Mjh3Z2dMUWwvVkxTRnJrSmVsClZ4ZUlKQlI1eDFHMUVub3pQa0o3ek5ZZWFYNko2STR3ek40emZmeWZLNXY5NStFdzBYZHQydFpGb1pTTGY4V2IKUTlWdmtLVm4wRHRyVlV0T3RPU0Q3U1F6cVNhOXQ1aHg5K0hHWFJBMGlpTWRrMnhVd0htRGhXNjhoYnRwK1NtcQpYYkFic2JvVTVYNktzcW9uV1BuTVN1aVFselY4cjFtY2lwa1FHSjhnWWZkdnk3QWlnRDBma2d5YXZWSjB1bjlFCi9HNW9qTjZ1bER2b0ZMOUptUmJYcXlTZEZXSXUwbU16TmhUVQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
server: https://192.168.2.213:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURFekNDQWZ1Z0F3SUJBZ0lJRW9hd1hFRUNzTUV3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBME1URXhNakkxTURSYUZ3MHlNekEwTVRFeE1qSTFNRFphTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXNENDNROVdFakZpRzZSK1EKbXNWNnJlZmJ5Q1RYeFRHM2R0VGh1ajR4eXNQM0lxSkY2YVowUUpPbWxaUHYyRjRmNGp2UWllcjJmVloydVM5WQpuME94bkZJa2p0dUMwODlibEJQL2J1VGo4TitLSDJoQnM5dVB3UmZxYjBIZWFUcU90YzRHZkZGdWF3NWk4UmZFClNZMktVdkx1OG5VM1lDT1dwcGNUSWJQeVJpQk4rYktnVU1KaFNoRGpEMWRhbDBicWtpUzFRVnd4SVNYdm50Z3QKWkloSzkwVnI5RWRlekJhYjdJRXhFbkxxdVVLR3JvZVFWS09ZdXNkejJnVVVieS9pejNPWENmWitpR21GSGs0MwpzbWF3SUV5OUN1Yy9FWVVVaVcwdklWaTdVYXRsUGhSUytCZFhGdDI5KzdHczl5dmdOVkhIcS9reWEzYXNQKzFRCk9sVzgwd0lEQVFBQm8wZ3dSakFPQmdOVkhROEJBZjhFQkFNQ0JhQXdFd1lEVlIwbEJBd3dDZ1lJS3dZQkJRVUgKQXdJd0h3WURWUjBqQkJnd0ZvQVVJVXlNcFhyZEYzTkszc1Z0Q0NCZVpLc1VURHd3RFFZSktvWklodmNOQVFFTApCUUFEZ2dFQkFDdmx0TF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MS85eVlab1hGL1VwOStuUkNmTy9HRGNpeU5Uc0RvY1UzQllaZnBSUExFYXdOUHNoaE0wSUphCkdWeHYvcUV6U2M4eGFvdXZjdUFBWVFLQmdHSThYYTlCSTZFNWg3a0NjeG1jL1JoajFhVkw0ZEdmN2doZ2Frc3UKOG45Z0QzSVBLTXFpYnpRQ3F1TytyVkMrU2lNMFkvVkk4RXhnVXc0REJQa0x5dEVmMEVsaEg0K1JJUDNEd3hNNgpNbXdVdjQwc044bitVYnZQRU5RdGM3N1d1L0FkWENkS0JaUU5WaHBhN1FSc1dxTFpjSlZSTXJOL1hHdEc0UERBCitNaEZBb0dBUUpHSnIzcE5JZVpMMDhhaGJmTEZPTVpScERDaTZEdmF2VU9oSkZEWWZXa0pnNWl2YSt1dVF4bFkKaWNJUmRtWXllekk3QjdwaTRMY3RBTFNqQUtOZGl4WkQxeDI0dDlKTWZYWkdPQmd2MmpueXR4YkZsVUh6UWk3OQo0ajY5a0NQaFdMNmhORWhTOFEwbnhKSVRMalhHMW9mL3F6eUJlV2x1SklLRHRzaVVEL1E9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tcG==
EOF
测试
]# kubectl get node
NAME STATUS ROLES AGE VERSION
a Ready control-plane,master 38h v1.20.9
b Ready <none> 38h v1.20.9
c Ready <none> 38h v1.20.9
结语
… …
更多推荐
已为社区贡献25条内容
所有评论(0)