当前位置:   article > 正文

基于Centos7安装k8s集群(k8s+crio+podman)_安装k8s podman

安装k8s podman

参考:k8s+crio+podman搭建集群

一、前言

在传统的 k8s集群中,使用docker engine做为底层的容器管理软件的,而docker engine因为不是k8s亲生的解决方案,所以实际使用中会有更多的分层。k8s为了调用docker engine,专门写了一个 dockershim做为 CRI,而在1.20版本的时候,k8s就宣布停止更新dockershim了,也就是说再往后的版本就不推荐使用 k8s+dockershim+docker engine的方案了。
而k8s官方比较推荐的解决方案中,官方比较推荐的是 cri-o或者 containerd,前者是基于开放容器计划(OCI)的实现,后者是基于docker的containerd,后脱离出来进行独立开发的组件,现归属于 CNCF组织。

二、CRI-O, Containerd, Docker daemon 对比

三者区别:

1. cri-o是 cri的实现,可以直接调用底层的runc
2. containerd是 CRI-Containerd的实现,可以调用底层的runc
3. docker需要先调用dockershim,然后调用docker,再调用containerd,最后调用底层的runc:
docker --> dockershim --> docker --> containerd --> runc

三者区别如图:

三、k8s+crio+podman实现

3.1 podman安装

参考:docker的平替–podman - eryoung2 - 博客园

三台机都需要安装podman

3.2 k8s的安装

参考: kubernetes 搭建集群 - eryoung2 - 博客园

三台机都需要安装kubelet/kubeadm/kubectl,并启动kubelet

3.2 cri-o的安装

3.2.1 Ubuntu(18.04)安装cri-o
3.2.1.1 准备
  1. $. modprobe overlay # 打开overlay
  2. $. modprobe br_netfilter # 打开netfilter
  3. $. cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF #内核处理
  4. net.bridge.bridge-nf-call-iptables = 1
  5. net.ipv4.ip\_forward = 1
  6. net.bridge.bridge-nf-call-ip6tables = 1
  7. EOF
  8. $. sysctl --system
  9. $. swapoff -a #kube scheduler要求关闭swap
3.2.1.2 安装CRI-O
  1. # 指定版本
  2. $. OS=xUbuntu_18.04
  3. $. CRIO\_VERSION=1.23
  4. # 加源
  5. $. echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
  6. $. echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO\_VERSION/$OS/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO\_VERSION.list
  7. # 加key
  8. $. curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$CRIO\_VERSION/$OS/Release.key | sudo apt-key add -
  9. $. curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key add -
  10. # 安装
  11. $. sudo apt update -y
  12. $. sudo apt install cri-o cri-o-runc cri-tools -y
3.2.1.3 检查CRI-O
  1. $. apt show cri-o
  2. Package: cri-o
  3. Version: 1.23.3~0
  4. Priority: optional
  5. Section: devel
  6. Maintainer: Peter Hunt <haircommander@fedoraproject.org>
  7. Installed-Size: 98.3 MB
  8. Depends: libgpgme11, libseccomp2, conmon, containers-common (>= 0.1.27) | golang-github-containers-common, tzdata
  9. Suggests: cri-o-runc | runc (>= 1.0.0), containernetworking-plugins
  10. Replaces: cri-o-1.19, cri-o-1.20, cri-o-1.21, cri-o-1.22
  11. Homepage: https://github.com/cri-o/cri-o
  12. Download-Size: 19.9 MB
  13. APT-Manual-Installed: yes
  14. APT-Sources: http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/1.23/xUbuntu_18.04 Packages
  15. Description: OCI-based implementation of Kubernetes Container Runtime Interface.
  16. N: Ignoring file 'ystemctlqq' in directory '/etc/apt/sources.list.d/' as it has no filename extension
  1. $. systemctl enable crio.service
  2. $. systemctl start crio.service
  1. $. systemctl status crio
  2. ● crio.service - Container Runtime Interface for OCI (CRI-O)
  3. Loaded: loaded (/usr/lib/systemd/system/crio.service; enabled; vendor preset: enabled)
  4. Active: active (running) since Wed 2022-07-13 01:26:03 CST; 16h ago
  5. Docs: https://github.com/cri-o/cri-o
  6. Main PID: 5338 (crio)
  7. Tasks: 15
  8. CGroup: /system.slice/crio.service
  9. └─5338 /usr/bin/crio
3.2.1.4 使用cri-o

查看状态

  1. root@home:~# crictl info
  2. {
  3. "status": {
  4. "conditions": [
  5. {
  6. "type": "RuntimeReady",
  7. "status": true,
  8. "reason": "",
  9. "message": ""
  10. },
  11. {
  12. "type": "NetworkReady",
  13. "status": true,
  14. "reason": "",
  15. "message": ""
  16. }
  17. ]
  18. }
  19. }

查看镜像

  1. root@home:~# crictl images
  2. IMAGE TAG IMAGE ID SIZE
  3. docker.io/calico/cni v3.23.2 a87d3f6f1b8fd 263MB
  4. docker.io/calico/node v3.23.2 a3447b26d32c7 224MB
  5. docker.io/library/nginx latest 41b0e86104ba6 146MB
  6. k8s.gcr.io/coredns/coredns v1.8.6 a4ca41631cc7a 47MB
  7. k8s.gcr.io/etcd 3.5.3-0 aebe758cef4cd 301MB
  8. k8s.gcr.io/kube-apiserver v1.24.2 d3377ffb7177c 131MB
  9. k8s.gcr.io/kube-controller-manager v1.24.2 34cdf99b1bb3b 121MB
  10. k8s.gcr.io/kube-proxy v1.24.2 a634548d10b03 112MB
  11. k8s.gcr.io/kube-scheduler v1.24.2 5d725196c1f47 52.3MB
  12. k8s.gcr.io/pause 3.6 6270bb605e12e 690kB
  13. k8s.gcr.io/pause 3.7 221177c6082a8 718kB
3.2.2 Centos(7)安装cri-o
3.2.2.1 准备
  1. $. VERSION=1.22
  2. $. sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/CentOS_7/devel:kubic:libcontainers:stable.repo
  3. $. sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:${VERSION}.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:${VERSION}/CentOS_7/devel:kubic:libcontainers:stable:cri-o:${VERSION}.repo
3.2.2.2 安装
  1. $. yum update -y
  2. $. yum install cri-o cri-tools -y
3.2.2.3 查看cri-o版本
  1. [root@node1 systemd]# rpm -qi cri-o
  2. Name : cri-o
  3. Epoch : 0
  4. Version : 1.22.5
  5. Release : 2.2.el7
  6. Architecture: x86_64
  7. Install Date: 2022年07月13日 星期三 01时36分47秒
  8. Group : Unspecified
  9. Size : 236845729
  10. License : ASL 2.0
  11. Signature : RSA/SHA256, 2022年07月10日 星期日 12时53分28秒, Key ID 4d64390375060aa4
  12. Source RPM : cri-o-1.22.5-2.2.el7.src.rpm
  13. Build Date : 2022年07月10日 星期日 12时53分00秒
  14. Build Host : sheep87
  15. Relocations : (not relocatable)
  16. Vendor : obs://build.opensuse.org/devel:kubic
  17. URL : https://github.com/cri-o/cri-o
  18. Summary : Open Container Initiative-based implementation of Kubernetes Container Runtime Interface
  19. Description :
  20. Open Container Initiative-based implementation of Kubernetes Container Runtime
  21. Interface.
3.2.2.4 启动cri-o
$. systemctl enable crio --now 
3.2.2.5 查看cri-o状态
  1. [root@node1 systemd]# systemctl status crio
  2. ● crio.service - Container Runtime Interface for OCI (CRI-O)
  3. Loaded: loaded (/usr/lib/systemd/system/crio.service; enabled; vendor preset: disabled)
  4. Active: active (running) since 三 2022-07-13 01:41:06 CST; 16h ago
  5. Docs: https://github.com/cri-o/cri-o
  6. Main PID: 24127 (crio)
  7. Tasks: 15
  8. Memory: 13.7M
  9. CGroup: /system.slice/crio.service
  10. └─24127 /usr/bin/crio

三台机都安装cri-o并启动。

四、K8S启动

4.1 创建k8s集群

在master上,执行下列命令:

  1. $. kubeadm init \
  2. --apiserver-advertise-address 192.168.1.150 \
  3. --apiserver-bind-port 6443 \
  4. --kubernetes-version 1.24.2 \
  5. --pod-network-cidr 10.244.0.0/16
  • --apiserver-advertise-address 集群master地址

  • --image-repository 由于默认拉取镜像地址k8s.gcr.io国内无法访问,这里指定阿里云镜像仓库地址

  • --kubernetes-version K8s版本,与上面安装的一致

  • --service-cidr 集群内部虚拟网络,Pod统一访问入口

  • --pod-network-cidr Pod网络,与下面部署的CNI网络组件yaml中保持一致

初始化之后,会输出一个join命令,先复制出来,node节点加入master会使用。

然后等5分钟,k8s集群的master node完成创建。

  1. Your Kubernetes control-plane has initialized successfully!
  2. To start using your cluster, you need to run the following as a regular user:
  3. mkdir -p $HOME/.kube
  4. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  5. sudo chown $(id -u):$(id -g) $HOME/.kube/config
  6. Alternatively, if you are the root user, you can run:
  7. export KUBECONFIG=/etc/kubernetes/admin.conf
  8. You should now deploy a pod network to the cluster.
  9. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  10. https://kubernetes.io/docs/concepts/cluster-administration/addons/
  11. Then you can join any number of worker nodes by running the following on each as root:
  12. kubeadm join 192.168.1.150:6443 --token gjxt6y.0wljlhfkjz90v12m --discovery-token-ca-cert-hash sha256:d69fc5929e442210c97ab85c05a8c2906f5819a74d5b0fa3481032d6a8f3fc07
  13. 1234567891011121314151617181920

在所有node机器节点运行命令:

  1. $. mkdir -p $HOME/.kube
  2. $. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3. $. sudo chown $(id -u):$(id -g) $HOME/.kube/config
  1. # 否则会报错
  2. The connection to the server localhost:8080 was refused - did you specify the right host or port?

4.2 检查集群

在以上所有内容都完成之后,查看nodes或者pods:

  1. root@home:~# kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. home Ready control-plane 179m v1.24.2
  4. node1 Ready <none> 179m v1.24.2
  5. node2 Ready <none> 179m v1.24.2
  6. root@home:~# kubectl get pods -A
  7. NAMESPACE NAME READY STATUS RESTARTS AGE
  8. kube-system coredns-6d4b75cb6d-4wxjh 1/1 Running 0 179m
  9. kube-system coredns-6d4b75cb6d-7qxpv 1/1 Running 0 179m
  10. kube-system etcd-home 1/1 Running 2 3h
  11. kube-system kube-apiserver-home 1/1 Running 2 3h
  12. kube-system kube-controller-manager-home 1/1 Running 2 3h
  13. kube-system kube-proxy-9w7mf 1/1 Running 0 179m
  14. kube-system kube-proxy-hpw6c 1/1 Running 0 179m
  15. kube-system kube-proxy-tbpr8 1/1 Running 0 179m
  16. kube-system kube-scheduler-home 1/1 Running 2 3h

鸣谢

  1. Using CRI-O as container runtime for Kubernetes

  1. Ubuntu安装CRI-O

  1. Install CRI-O Container Runtime on CentOS 8 / CentOS 7 | ComputingForGeeks

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/159074?site
推荐阅读
相关标签
  

闽ICP备14008679号