Debian安装k8s记录

Debian安装k8s记录

  • 在master和node上安装kube
  • 安装master
  • 安装node
  • 遇到的问题汇总
    • 1、kubelet.service报错 failed to pull image "registry.k8s.io/pause:3.6"
    • 2、node重启后报错,failed: open /run/flannel/subnet.env: no such file or directory

在master和node上安装kube

apt-get update && apt-get install -y apt-transport-https
# 添加key
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg > /etc/apt//etc/apt/trusted.gpg.d/aliyun-kubernetes.asc

# 添加软件源
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

# 执行更新并安装
apt-get update
apt-get install -y kubelet kubeadm kubectl

安装master

cat <<EOF >/etc/default/kubelet
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.6"
EOF

# 关闭swap
sudo swapoff -a

# 初始化
sudo kubeadm init --kubernetes-version v1.27.4 --image-repository registry.aliyuncs.com/google_containers --apiserver-advertise-address 0.0.0.0 --service-cidr 10.1.0.0/16 --pod-network-cidr 10.2.0.0/16

# 安装pod网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

这时,master应该就安装完成了

安装node

sudo kubeadm join 192.168.8.5:6443 --token XXXXXX.XXXXXXXXXXXXXXXX --discovery-token-ca-cert-hash sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

其中token和hash来自master初始化最后的输出,地址和端口是master的apiserver,也可以在master节点通过下述命令获得完整命令

kubeadm token create --print-join-command

遇到的问题汇总

1、kubelet.service报错 failed to pull image “registry.k8s.io/pause:3.6”

# 生成containerd默认配置
containerd config default  > /etc/containerd/config.toml

#修改/etc/containerd/config.toml
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"

# 重启containerd.service、kubelet.service
systemctl daemon-reload
systemctl restart containerd.service
systemctl restart kubelet.service

2、node重启后报错,failed: open /run/flannel/subnet.env: no such file or directory

添加文件/run/flannel/subnet.env,添加一下内容,注意网络与kubectl init中的一致

FLANNEL_NETWORK=10.2.0.0/16
FLANNEL_SUBNET=10.2.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true

目前了解到的方法只有手动添加,不知道怎么自动化生成

你可能感兴趣的:(debian,kubernetes,运维)