0%

更新:Debian 11 配置Kubernetes CRI-O

安装CRI-O

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 设置环境变量
OS=Debian_11
VERSION=1.27

# 添加源
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list

# 导入key
curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | apt-key add -
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | apt-key add -

# 更新
apt-get update

# 安装 cri-o
apt-get install cri-o cri-o-runc

# 启动cri-o
service crio start

安装Kubernetes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# disable swap
swapoff -a
# 编辑 /etc/fstab 去掉 swap 的配置

# 配置启动加载模块
modprope br_netfilter
# 在 /etc/modules 追加 br_netfilter,以便重启后自动加载 br_netfilter

# 配置
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
EOF
sysctl --system

# install k8s,k8s的版本需要与crio的版本对应,crio是1.27的,k8s的也是1.27
apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

KUBE_VERSION=1.27.1-00
apt-get update
apt-get install -y kubelet=$KUBE_VERSION kubeadm=$KUBE_VERSION kubectl=$KUBE_VERSION
# 锁定版本
apt-mark hold kubelet kubeadm kubectl

配置Kubernetes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 使用kubeadm初始化
PUBLICIP=xxx.xxx.xxx.xxx
kubeadm init --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/16 --apiserver-advertise-address=$PUBLICIP --cri-socket=/var/run/crio/crio.sock
# 如果不需要设定publicip,可以省略这参数

# 配置
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

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

# 确认下是否配置成功
kubectl get nodes -n kube-system
kubectl get pods -n kube-system

# 配置 dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
# 配置 dashboard访问用户参考
# https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md