k8s 集群配置
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 |
理解 kubeconfig
本文是使用 kubectl 来管理 k8s 集群, 所以你需要知道 kubeconfig 的配置结构, 也可以直接 copy-paste
kubectl 管理优势: 可通过切换 context 上下文, 更换操作集群 => 可管理集群联邦
推荐: 理解/使用 kubeconfig 管理集群 – CSDN
思路整理:
首先理清思路, 要使用 wsl 管理远程 k8s 集群
- 确保 wsl 能够连接到 k8s 集群
- 要管理 k8s 集群, 就需要在 wsl 上安装 kubectl, 不再需要 kubeadm 与 kubelet
- 要想使用 kubectl 管理集群, 就需要集群的 kubeconfig 与 集群证书
在 wsl 上安装 kubectl
# 安装依赖
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
拷贝 kubeconfig
登到 k8s 集群的 master 节点, 把 kubeconfig 拷贝到 wsl
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
测试 kubectl
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
参考: