IP | Host | 配置 |
---|---|---|
11.0.1.150 | master1 (keepalived+haproxy) | 2C 4G 30G |
11.0.1.148 | master2 (keepalived+haproxy) | 2C 4G 30G |
11.0.1.149 | node1 | 2C 4G 30G |
本文是使用 kubectl 来管理 k8s 集群, 所以你需要知道 kubeconfig 的配置结构, 也可以直接 copy-paste
kubectl 管理优势: 可通过切换 context 上下文, 更换操作集群 => 可管理集群联邦
推荐: 理解/使用 kubeconfig 管理集群 – CSDN
首先理清思路, 要使用 wsl 管理远程 k8s 集群
# 安装依赖
apt install apt-transport-https ca-certificates -y
apt install vim lsof net-tools zip unzip tree wget curl bash-completion pciutils gcc make lrzsz tcpdump bind9-utils -y
# 编辑镜像源文件,文件末尾加入阿里云k8s镜像源配置
echo 'deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main' >> /etc/apt/sources.list
#更新证书
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add
#更新源
apt update
# 查看 kubeadm 版本
apt-cache madison kubeactl | grep 1.28
apt-get install -y kubectl=1.28.1-00
apt install bash-completion -y
cat << EOF >> ~/.profile
alias k='kubectl'
source <(kubectl completion bash)
complete -F __start_kubectl k
EOF
source ~/.profile
ssh 免密登录
echo "172.28.18.117 wsl" >> /etc/hosts
# 测试链接
ping wsl
# 拷贝公钥
ssh-copy-id -i ~/.ssh/id_rsa.pub root@wsl
如果有安全需要的话, 就不要把建立 wsl 与 master 的免密登录
拷贝 kubeconfig
ssh root@wsl mkdir /root/.kube
scp /root/.kube/config root@wsl:/root/.kube/config
root@MKT:~# k get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
calico-apiserver calico-apiserver-69fc754d76-9w7p6 1/1 Running 1 (17m ago) 46h
calico-apiserver calico-apiserver-69fc754d76-kdxt4 1/1 Running 1 (21m ago) 46h
calico-system calico-kube-controllers-b9dcc57c4-gzlhk 1/1 Running 1 (21m ago) 46h
calico-system calico-node-5jckf 1/1 Running 1 (17m ago) 46h
calico-system calico-node-gq882 1/1 Running 1 (21m ago) 46h
calico-system calico-node-zksvz 1/1 Running 1 (21m ago) 45h
calico-system calico-typha-5cdb9d5d59-tnjzh 1/1 Running 1 (17m ago) 46h
calico-system calico-typha-5cdb9d5d59-z7tnk 1/1 Running 1 (21m ago) 45h
calico-system csi-node-driver-j4648 2/2 Running 2 (21m ago) 46h
calico-system csi-node-driver-jf548 2/2 Running 2 (21m ago) 45h
calico-system csi-node-driver-p9b8p 2/2 Running 2 (17m ago) 46h
kube-system coredns-66f779496c-n4lwr 1/1 Running 1 46h
kube-system coredns-66f779496c-tmjx9 1/1 Running 1 (21m ago) 46h
kube-system etcd-master1 1/1 Running 3 (21m ago) 46h
kube-system etcd-master2 1/1 Running 1 (21m ago) 45h
kube-system kube-apiserver-master1 1/1 Running 3 (21m ago) 46h
kube-system kube-apiserver-master2 1/1 Running 1 (21m ago) 45h
kube-system kube-controller-manager-master1 1/1 Running 5 (21m ago) 46h
kube-system kube-controller-manager-master2 1/1 Running 2 (20m ago) 45h
kube-system kube-proxy-9tjjg 1/1 Running 1 (17m ago) 46h
kube-system kube-proxy-chcc5 1/1 Running 1 (21m ago) 45h
kube-system kube-proxy-mrp2v 1/1 Running 1 (21m ago) 46h
kube-system kube-scheduler-master1 1/1 Running 5 (21m ago) 46h
kube-system kube-scheduler-master2 1/1 Running 1 (21m ago) 45h
tigera-operator tigera-operator-55585899bf-tcdhv 1/1 Running 4 (17m ago) 46h
参考:
- https://kubernetes.io/zh-cn/docs/concepts/configuration/organize-cluster-access-kubeconfig/