基于docker和cri-dockerd部署k8sv1.26.3

这篇具有很好参考价值的文章主要介绍了基于docker和cri-dockerd部署k8sv1.26.3。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

cri-dockerd是什么?

cri-dockerd,docker,kubernetes,容器

  在 Kubernetes v1.24 及更早版本中,我们使用docker作为容器引擎在k8s上使用时,依赖一个dockershim的内置k8s组件;k8s v1.24发行版中将dockershim组件给移除了;取而代之的就是cri-dockerd(当然还有其它容器接口);简单讲CRI就是容器运行时接口(Container Runtime Interface,CRI),也就是说cri-dockerd就是以docker作为容器引擎而提供的容器运行时接口;即我们想要用docker作为k8s的容器运行引擎,我们需要先部署好cri-dockerd;用cri-dockerd来与kubelet交互,然后再由cri-dockerd和docker api交互,使我们在k8s能够正常使用docker作为容器引擎;

  好了,接下来我们先来说一下部署环境

  OS:Ubuntu 22.04.2

  Container Runtime:Docker CE 23.0.1

  CRI:cri-dockerd:0.3.0

cri-dockerd,docker,kubernetes,容器

  以下步骤需要在每个服务器上都要部署

  部署时间服务chronyd

1

apt update && apt install chrony

  配置阿里云时间服务器

1

pool ntp1.aliyun.com        iburst maxsources 4

  提示:在/etc/chrony/chrony.conf中加入上述配置,将其他pool开头的配置注释掉;

   重启chrony,并验证

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

29

30

root@k8s-master01:~# systemctl restart chrony

root@k8s-master01:~# systemctl status chrony

● chrony.service - chrony, an NTP client/server

     Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)

     Active: active (running) since Sat 2023-04-01 20:22:44 CST; 6s ago

       Docs: man:chronyd(8)

             man:chronyc(1)

             man:chrony.conf(5)

    Process: 3052 ExecStart=/usr/lib/systemd/scripts/chronyd-starter.sh $DAEMON_OPTS (code=exited, status=0/SUCCESS)

   Main PID: 3061 (chronyd)

      Tasks: 2 (limit: 4530)

     Memory: 1.3M

        CPU: 40ms

     CGroup: /system.slice/chrony.service

             ├─3061 /usr/sbin/chronyd -F 1

             └─3062 /usr/sbin/chronyd -F 1

Apr 01 20:22:44 k8s-master01.ik8s.cc systemd[1]: Starting chrony, an NTP client/server...

Apr 01 20:22:44 k8s-master01.ik8s.cc chronyd[3061]: chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +>

Apr 01 20:22:44 k8s-master01.ik8s.cc chronyd[3061]: Frequency -3.785 +/- 18.293 ppm read from /var/lib/chrony/chrony.drift

Apr 01 20:22:44 k8s-master01.ik8s.cc chronyd[3061]: Using right/UTC timezone to obtain leap second data

Apr 01 20:22:44 k8s-master01.ik8s.cc chronyd[3061]: Loaded seccomp filter (level 1)

Apr 01 20:22:44 k8s-master01.ik8s.cc systemd[1]: Started chrony, an NTP client/server.

Apr 01 20:22:50 k8s-master01.ik8s.cc chronyd[3061]: Selected source 120.25.115.20 (ntp1.aliyun.com)

Apr 01 20:22:50 k8s-master01.ik8s.cc chronyd[3061]: System clock TAI offset set to 37 seconds

root@k8s-master01:~# chronyc sources

MS Name/IP address         Stratum Poll Reach LastRx Last sample              

===============================================================================

^* ntp1.aliyun.com               2   6    17    13   +950us[+3545us] +/-   23ms

root@k8s-master01:~#

  提示:使用chronyc sources命令能够看到从那个服务器同步时间,能够看我们配置的服务器地址就表示chrony服务配置没有问题;

  借用hosts文件做主机名解析

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

root@k8s-master01:~# cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 k8s-server

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

192.168.0.51 kubeapi.ik8s.cc kubeapi

192.168.0.51 k8s-master01.ik8s.cc k8s-master01

192.168.0.52 k8s-master02.ik8s.cc k8s-master02

192.168.0.53 k8s-master03.ik8s.cc k8s-master03

192.168.0.54 k8s-node01.ik8s.cc k8s-node01

192.168.0.55 k8s-node02.ik8s.cc k8s-node02

192.168.0.56 k8s-node03.ik8s.cc k8s-node03

root@k8s-master01:~#

  各节点禁用swap设备

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

root@k8s-master01:~# swapoff  -a

root@k8s-master01:~# cat /etc/fstab

# /etc/fstab: static file system information.

#

# Use 'blkid' to print the universally unique identifier for a

# device; this may be used with UUID= as a more robust way to name devices

# that works even if disks are added and removed. See fstab(5).

#

# <file system> <mount point>   <type>  <options>       <dump>  <pass>

# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation

/dev/disk/by-id/dm-uuid-LVM-TjXApGigP3NsOAzv7UAMUgV9BdMSVlrxfAjm6qSYs1DxA8Nzmr2DKaODbQf48e2m / ext4 defaults 0 1

# /boot was on /dev/sda2 during curtin installation

/dev/disk/by-uuid/db6b3290-0968-4e77-bdd7-ddc849cdda26 /boot ext4 defaults 0 1

#/swap.img      none    swap    sw      0       0

root@k8s-master01:~#

  提示:将fstab文件中,又不安swap设备的配置注释掉即可;

  各节点禁用默认配置防火墙

1

2

3

4

5

root@k8s-master01:~# ufw disable

Firewall stopped and disabled on system startup

root@k8s-master01:~# ufw status

Status: inactive

root@k8s-master01:~#

  安装docker

1

2

3

4

~# apt install apt-transport-https ca-certificates curl software-properties-common -y

~# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -

~# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

~# apt update<br>~# apt install docker-ce

  配置docker容器引擎使用systemd作为CGroup的驱动

1

2

3

4

5

6

7

8

9

10

11

~# cat /etc/docker/daemon.json

{

        "registry-mirrors": [

        ],

        "exec-opts": ["native.cgroupdriver=systemd"],

        "log-driver""json-file",

        "log-opts": {

                  "max-size""200m"

        },

        "storage-driver""overlay2" 

}

  提示:如果你没有代理,也可以使用registry-mirrors来指明使用的镜像加速服务;

  启动docker服务

1

systemctl daemon-reload && systemctl start docker && systemctl enable docker

  配置docker使用代理服务

cri-dockerd,docker,kubernetes,容器

1

2

3

Environment="HTTP_PROXY=http://$PROXY_SERVER_IP:$PROXY_PORT"

Environment="HTTPS_PROXY=https://$PROXY_SERVER_IP:$PROXY_PORT"

Environment="NO_PROXY=127.0.0.0/8,172.17.0.0/16,10.244.0.0/16,192.168.0.0/16,10.0.0.0/8,cluster.local"

  提示:在/usr/lib/systemd/system/docker.service文件中加入以上配置,把自己的代理服务器地址更换上述$PROXY_SERVER_IP:$PROXY_PORT

即可;

  重载和重启docker服务

1

2

~# systemctl daemon-reload

~# systemctl restart docker

  安装cri-dockerd

1

2

~# curl -LO https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.0/cri-dockerd_0.3.0.3-0.ubuntu-jammy_amd64.deb

~# apt install ./cri-dockerd_0.3.0.3-0.ubuntu-jammy_amd64.deb

  提示:安装完cri-dockerd以后,对应服务会自动启动;

  在各主机上生成kubelet和kubeadm等相关程序包的仓库

1

2

3

4

5

6

~# apt update && apt install -y apt-transport-https curl

~# curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

~# cat <<EOF >/etc/apt/sources.list.d/kubernetes.list

deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main

EOF

~# apt update

  安装kubelet、kubeadm和kubectl

1

2

~# apt install -y kubelet kubeadm kubectl

~# systemctl enable kubelet

  确认版本

1

2

3

root@k8s-master01:~# kubeadm version

kubeadm version: &version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.3", GitCommit:"9e644106593f3f4aa98f8a84b23db5fa378900bd", GitTreeState:"clean", BuildDate:"2023-03-15T13:38:47Z", GoVersion:"go1.19.7", Compiler:"gc", Platform:"linux/amd64"}

root@k8s-master01:~#

  整合kubelet和cri-dockerd

  配置cri-dockerd

cri-dockerd,docker,kubernetes,容器

1

2

ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/

cni/cache --cni-conf-dir=/etc/cni/net.d

  提示:在/usr/lib/systemd/system/cri-docker.service文件中添加上如上配置;--network-plugin:指定网络插件规范的类型,这里要使用CNI;--cni-bin-dir:指定CNI插件二进制程序文件的搜索目录;--cni-cache-dir:CNI插件使用的缓存目录;--cni-conf-dir:CNI插件加载配置文件的目录;

  重启cri-dockerd服务

1

~# systemctl daemon-reload && systemctl restart cri-docker

  配置kubelet

1

2

3

root@k8s-master01:~# cat /etc/sysconfig/kubelet

KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime-endpoint=/run/cri-dockerd.sock"

root@k8s-master01:~#

  提示:如果没有sysconfig目录,请先创建,然后再创建kubelet文件;这一步就是告诉kubelet cri-dockerd的接口在哪里;该配置不是必须的,我们也可以在初始化集群时在kubeadm命令上使用“--cri-socket unix:///run/cri-dockerd.sock”选项来告诉kubelet cri-dockerd的socket文件路径;

  初始化第一个master节点

  列出镜像信息

1

2

3

4

5

6

7

8

9

root@k8s-master01:~# kubeadm config images list

registry.k8s.io/kube-apiserver:v1.26.3

registry.k8s.io/kube-controller-manager:v1.26.3

registry.k8s.io/kube-scheduler:v1.26.3

registry.k8s.io/kube-proxy:v1.26.3

registry.k8s.io/pause:3.9

registry.k8s.io/etcd:3.5.6-0

registry.k8s.io/coredns/coredns:v1.9.3

root@k8s-master01:~#

  提示:k8s的镜像默认是谷歌仓库地址,需要代理才可以正常访问;如果你没有代理,请使用阿里云仓库也是可以的;用--image-repository="registry.aliyuncs.com/google_containers"来指定使用阿里云镜像仓库中的镜像部署k8s集群;

  下载镜像

1

2

3

4

root@k8s-master01:~# kubeadm config images pull

Found multiple CRI endpoints on the host. Please define which one do you wish to use by setting the 'criSocket' field in the kubeadm configuration file: unix:///var/run/containerd/containerd.sock, unix:///var/run/cri-dockerd.sock

To see the stack trace of this error execute with --v=5 or higher

root@k8s-master01:~#

  提示:这里是让我们指定cri-dockerd的socket文件路径;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

root@k8s-master01:~# kubeadm config images pull --cri-socket unix:///var/run/cri-dockerd.sock

[config/images] Pulled registry.k8s.io/kube-apiserver:v1.26.3

[config/images] Pulled registry.k8s.io/kube-controller-manager:v1.26.3

[config/images] Pulled registry.k8s.io/kube-scheduler:v1.26.3

[config/images] Pulled registry.k8s.io/kube-proxy:v1.26.3

[config/images] Pulled registry.k8s.io/pause:3.9

[config/images] Pulled registry.k8s.io/etcd:3.5.6-0

[config/images] Pulled registry.k8s.io/coredns/coredns:v1.9.3

root@k8s-master01:~# docker images

REPOSITORY                                TAG       IMAGE ID       CREATED         SIZE

registry.k8s.io/kube-apiserver            v1.26.3   1d9b3cbae03c   2 weeks ago     134MB

registry.k8s.io/kube-controller-manager   v1.26.3   ce8c2293ef09   2 weeks ago     123MB

registry.k8s.io/kube-scheduler            v1.26.3   5a7904736932   2 weeks ago     56.4MB

registry.k8s.io/kube-proxy                v1.26.3   92ed2bec97a6   2 weeks ago     65.6MB

registry.k8s.io/etcd                      3.5.6-0   fce326961ae2   4 months ago    299MB

registry.k8s.io/pause                     3.9       e6f181688397   5 months ago    744kB

registry.k8s.io/coredns/coredns           v1.9.3    5185b96f0bec   10 months ago   48.8MB

root@k8s-master01:~#

  提示:用上述命令就可以把初始化k8s集群所需镜像pull到本地;

  初始化第一个master节点

1

2

3

4

5

6

7

8

kubeadm init \

        --control-plane-endpoint="kubeapi.ik8s.cc" \

        --kubernetes-version=v1.26.3 \

        --pod-network-cidr=10.244.0.0/16 \

        --service-cidr=10.96.0.0/12 \

        --token-ttl=0 \

        --cri-socket unix:///run/cri-dockerd.sock \

        --upload-certs

  提示:如果要指定仓库地址,请使用--image-repository选项来指定对应仓库;

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

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

root@k8s-master01:~# kubeadm init \

>         --control-plane-endpoint="kubeapi.ik8s.cc" \

>         --kubernetes-version=v1.26.3 \

>         --pod-network-cidr=10.244.0.0/16 \

>         --service-cidr=10.96.0.0/12 \

>         --token-ttl=0 \

>         --cri-socket unix:///run/cri-dockerd.sock \

>         --upload-certs

[init] Using Kubernetes version: v1.26.3

[preflight] Running pre-flight checks

[preflight] Pulling images required for setting up a Kubernetes cluster

[preflight] This might take a minute or two, depending on the speed of your internet connection

[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

[certs] Using certificateDir folder "/etc/kubernetes/pki"

[certs] Generating "ca" certificate and key

[certs] Generating "apiserver" certificate and key

[certs] apiserver serving cert is signed for DNS names [k8s-master01.ik8s.cc kubeapi.ik8s.cc kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.0.51]

[certs] Generating "apiserver-kubelet-client" certificate and key

[certs] Generating "front-proxy-ca" certificate and key

[certs] Generating "front-proxy-client" certificate and key

[certs] Generating "etcd/ca" certificate and key

[certs] Generating "etcd/server" certificate and key

[certs] etcd/server serving cert is signed for DNS names [k8s-master01.ik8s.cc localhost] and IPs [192.168.0.51 127.0.0.1 ::1]

[certs] Generating "etcd/peer" certificate and key

[certs] etcd/peer serving cert is signed for DNS names [k8s-master01.ik8s.cc localhost] and IPs [192.168.0.51 127.0.0.1 ::1]

[certs] Generating "etcd/healthcheck-client" certificate and key

[certs] Generating "apiserver-etcd-client" certificate and key

[certs] Generating "sa" key and public key

[kubeconfig] Using kubeconfig folder "/etc/kubernetes"

[kubeconfig] Writing "admin.conf" kubeconfig file

[kubeconfig] Writing "kubelet.conf" kubeconfig file

[kubeconfig] Writing "controller-manager.conf" kubeconfig file

[kubeconfig] Writing "scheduler.conf" kubeconfig file

[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"

[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"

[kubelet-start] Starting the kubelet

[control-plane] Using manifest folder "/etc/kubernetes/manifests"

[control-plane] Creating static Pod manifest for "kube-apiserver"

[control-plane] Creating static Pod manifest for "kube-controller-manager"

[control-plane] Creating static Pod manifest for "kube-scheduler"

[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"

[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s

[apiclient] All control plane components are healthy after 5.503108 seconds

[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace

[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster

[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace

[upload-certs] Using certificate key:

e0ccb2457a9290a7b917e2a9c4eab81f6f1cd208db5b2bb863d91b51f922b8bf

[mark-control-plane] Marking the node k8s-master01.ik8s.cc as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]

[mark-control-plane] Marking the node k8s-master01.ik8s.cc as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]

[bootstrap-token] Using token: a6zxug.lq05a0itb783hv96

[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles

[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes

[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials

[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token

[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster

[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace

[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key

[addons] Applied essential addon: CoreDNS

[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of the control-plane node running the following command on each as root:

  kubeadm join kubeapi.ik8s.cc:6443 --token a6zxug.lq05a0itb783hv96 \

        --discovery-token-ca-cert-hash sha256:07095e3d4747fdac7e44efeb9f657d102c48c8bbcec608d98648e88cfe954791 \

        --control-plane --certificate-key e0ccb2457a9290a7b917e2a9c4eab81f6f1cd208db5b2bb863d91b51f922b8bf

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!

As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use

"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join kubeapi.ik8s.cc:6443 --token a6zxug.lq05a0itb783hv96 \

        --discovery-token-ca-cert-hash sha256:07095e3d4747fdac7e44efeb9f657d102c48c8bbcec608d98648e88cfe954791

root@k8s-master01:~#

  提示:能够看到上诉信息,说明第一个k8s主节点就初始化成功;按照上述提示,完成后续步骤即可;

  复制配置文件到本地用户家目录,并创建.kube目录

1

2

3

4

root@k8s-master01:~# mkdir -p $HOME/.kube

root@k8s-master01:~# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

root@k8s-master01:~# chown $(id -u):$(id -g) $HOME/.kube/config

root@k8s-master01:~#

  部署网络插件

  下载网络插件calico的部署清单

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

root@k8s-master01:~# wget https://docs.projectcalico.org/v3.25/manifests/calico.yaml --no-check-certificate

--2023-04-02 10:25:42--  https://docs.projectcalico.org/v3.25/manifests/calico.yaml

Resolving docs.projectcalico.org (docs.projectcalico.org)... 34.124.186.36, 34.126.184.144, 2406:da18:880:3801::c8, ...

Connecting to docs.projectcalico.org (docs.projectcalico.org)|34.124.186.36|:443... connected.

HTTP request sent, awaiting response... 301 Moved Permanently

Location: https://docs.tigera.io/archive/v3.25/manifests/calico.yaml [following]

--2023-04-02 10:25:44--  https://docs.tigera.io/archive/v3.25/manifests/calico.yaml

Resolving docs.tigera.io (docs.tigera.io)... 34.142.149.67, 18.139.194.139, 2406:da18:880:3800::c8, ...

Connecting to docs.tigera.io (docs.tigera.io)|34.142.149.67|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 238089 (233K) [text/yaml]

Saving to: ‘calico.yaml’

calico.yaml                                100%[=======================================================================================>] 232.51K  51.0KB/s    in 4.6s   

2023-04-02 10:25:50 (51.0 KB/s) - ‘calico.yaml’ saved [238089/238089]

root@k8s-master01:~#

  在k8s集群上应用清单

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

29

root@k8s-master01:~# kubectl apply -f calico.yaml

poddisruptionbudget.policy/calico-kube-controllers created

serviceaccount/calico-kube-controllers created

serviceaccount/calico-node created

configmap/calico-config created

customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipreservations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org created

clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created

clusterrole.rbac.authorization.k8s.io/calico-node created

clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created

clusterrolebinding.rbac.authorization.k8s.io/calico-node created

daemonset.apps/calico-node created

deployment.apps/calico-kube-controllers created

root@k8s-master01:~#

  查看节点是否准备就绪?对应calico pod是否running?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

root@k8s-master01:~# kubectl get nodes

NAME                   STATUS   ROLES           AGE   VERSION

k8s-master01.ik8s.cc   Ready    control-plane   11m   v1.26.3

root@k8s-master01:~# kubectl get pods -n kube-system

NAME                                           READY   STATUS    RESTARTS   AGE

calico-kube-controllers-57b57c56f-wvh56        1/1     Running   0          4m40s

calico-node-fjhf7                              1/1     Running   0          4m40s

coredns-787d4945fb-68js9                       1/1     Running   0          11m

coredns-787d4945fb-8q5l5                       1/1     Running   0          11m

etcd-k8s-master01.ik8s.cc                      1/1     Running   0          11m

kube-apiserver-k8s-master01.ik8s.cc            1/1     Running   0          11m

kube-controller-manager-k8s-master01.ik8s.cc   1/1     Running   0          11m

kube-proxy-dxmcz                               1/1     Running   0          11m

kube-scheduler-k8s-master01.ik8s.cc            1/1     Running   0          11m

root@k8s-master01:~#

  提示:能够看到master01已经准备就绪,对应pod也都正常running,到此第一个master节点就准备就绪;

  加入node节点

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

root@k8s-node01:~# kubeadm join kubeapi.ik8s.cc:6443 --token a6zxug.lq05a0itb783hv96 \

>         --discovery-token-ca-cert-hash sha256:07095e3d4747fdac7e44efeb9f657d102c48c8bbcec608d98648e88cfe954791 --cri-socket unix:///run/cri-dockerd.sock

[preflight] Running pre-flight checks

[preflight] Reading configuration from the cluster...

[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'

[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"

[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"

[kubelet-start] Starting the kubelet

[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:

* Certificate signing request was sent to apiserver and a response was received.

* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

root@k8s-node01:~#

  提示:能够看到上述信息表示node节点加入成功;这里需要注意的是,加入node节点,需要指定cri-dockerd的socket文件位置;

  验证:查看三个节点是否都以正常加入集群?

1

2

3

4

5

6

7

root@k8s-master01:~# kubectl get nodes

NAME                   STATUS   ROLES           AGE   VERSION

k8s-master01.ik8s.cc   Ready    control-plane   15m   v1.26.3

k8s-node01.ik8s.cc     Ready    <none>          53s   v1.26.3

k8s-node02.ik8s.cc     Ready    <none>          11s   v1.26.3

k8s-node03.ik8s.cc     Ready    <none>          5s    v1.26.3

root@k8s-master01:~#

  提示:可以看到现在有3个node节点,都处于就绪状态;

  验证:kube-system名称空间下的pods是否都running?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

root@k8s-master01:~# kubectl get pods -n kube-system

NAME                                           READY   STATUS    RESTARTS   AGE

calico-kube-controllers-57b57c56f-wvh56        1/1     Running   0          9m49s

calico-node-5wg79                              1/1     Running   0          92s

calico-node-fjhf7                              1/1     Running   0          9m49s

calico-node-h9rpm                              1/1     Running   0          86s

calico-node-s5p6c                              1/1     Running   0          2m14s

coredns-787d4945fb-68js9                       1/1     Running   0          16m

coredns-787d4945fb-8q5l5                       1/1     Running   0          16m

etcd-k8s-master01.ik8s.cc                      1/1     Running   0          16m

kube-apiserver-k8s-master01.ik8s.cc            1/1     Running   0          16m

kube-controller-manager-k8s-master01.ik8s.cc   1/1     Running   0          16m

kube-proxy-8twxn                               1/1     Running   0          86s

kube-proxy-dxmcz                               1/1     Running   0          16m

kube-proxy-fjqww                               1/1     Running   0          92s

kube-proxy-hdllg                               1/1     Running   0          2m14s

kube-scheduler-k8s-master01.ik8s.cc            1/1     Running   0          16m

root@k8s-master01:~#

  提示:可以看到kube-system名称空间下的pod都running且都是处于就绪状态;至此基于cri-dockerd和docker的单master节点的k8s集群就搭建好了文章来源地址https://www.toymoban.com/news/detail-784956.html

到了这里,关于基于docker和cri-dockerd部署k8sv1.26.3的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 飞天使-k8sv1.14二进制安装

    安装前准备 安装前设置分发脚本 开始安装k8s集群 cfssl 安装 部署kubectl命令行工具 创建admin证书和私钥 创建kubeconfig文件 部署ETCD集群 部署Flannel网络 kube-apiserver 高可用 KeepLived 部署 部署master节点 部署高可用kube-controller-manager集群 kube-controller-manager 创建权限 部署高可用kube-sc

    2024年02月12日
    浏览(31)
  • 云原生|kubernetes|使用cri-docker部署基于kubeadm-1.25.4的集群

    前言: kubernetes的部署从1.24版本开始后,弃用docker-shim,也就是说部署1.24版本后的集群不能使用docker-ce了。 比较清晰的解决方案有两个,一是使用containerd,这个是一个新的支持cri标准的shim,一个是使用cri-docker这样的中间插件形式, 一头通过CRI跟kubelet交互,另一头跟docker

    2024年02月07日
    浏览(68)
  • 【云原生-K8s】kubeadm搭建安装k8s集群v1.25版本完整教程【docker、网络插件calico、中间层cri-docker】

    从 k8s 1.24开始,dockershim已经从kubelet中移除,但因为历史问题docker却不支持kubernetes主推的CRI(容器运行时接口)标准,所以docker不能再作为k8s的容器运行时了,即从k8s v1.24开始不再使用docker了 但是如果想继续使用docker的话,可以在kubelet和docker之间加上一个中间层cri-docker。

    2024年02月03日
    浏览(34)
  • 基于Docker的K8s(Kubernetes)集群部署

    开始搭建k8s集群 三台服务器修改主机名称 关闭对话窗口,重新连接 三台主机名称呢就修改成功了。 接下来修改每台节点的 hosts 文件 所有节点关闭 setLinux 查看是否关闭成功 为每个节点添加 k8s 数据源 如果安装docker数据源找不到yum-config 所有节点安装kubelet kubelet安装中… k

    2024年02月08日
    浏览(81)
  • 基于ubuntu20.04安装kubernetes1.27.1(使用cri-docker)

    192.168.1.60 master 192.168.1.61 node1 192.168.1.62 node2 192.168.1.63 node3 不修改hostname会导致主机名相同,安装网络创建后,不同node节点的pod通信会有问题 2.3启动docker 配置service和socker文件 启动 dpkg 安装方便,不易出错 修改配置文件pause镜像使用过阿里源,默认使用的是国外的,下载不了

    2024年02月06日
    浏览(37)
  • docker守护进程dockerd

    Docker为守护程序和客户端使用不同的二进制文件。要运行守护程序,请输入dockerd 。dockerd 是 docker 架构中一个常驻在后台的系统进程,称为 docker daemon,dockerd 实际调用的还是 containerd 的 api 接口(rpc 方式实现),docker daemon 的作用主要有以下两方面: 接收并处理 docker client 发

    2024年02月16日
    浏览(28)
  • 浅谈 K8s CRI

    进入 K8s 的世界,会发现有很多方便扩展的 Interface,包括 CRI, CSI, CNI 等,将这些接口抽象出来,是为了更好的提供开放、扩展、规范等能力。 K8s CRI(Container Runtime Interface) 是 K8s 定义的一组与容器运行时进行交互的接口,用于将 K8s 平台与特定的容器运行时实现解耦。CRI 在 K

    2024年02月04日
    浏览(24)
  • 安卓手机部署ubuntu的lxc容器,并安装好dockerd

    刷机获取root是必须的,而且必需要有一个支持docker的内核。 检测当前设备支持docker的方法: 安装Termux并初始化。 这里给个安装包下载链接:[termux app链接]。 下载Moby的脚本用于检查缺少的内核功能 查看CONFIG都是绿字就行。 编译支持docker的安卓内核的方法,就不在此写了,

    2024年02月03日
    浏览(27)
  • k8s更新证书报multiple CRI endpoints错误

    当我需要扩展master节点时,在主节点执行kubeadm init phase upload-certs --upload-certs报错 当加上cri-socket参数仍旧行不通 kubeadm init phase upload-certs --upload-certs --help 查看,原因旧是没有这个–cri-socket选项 重新执行upload-certs并带上–config

    2024年01月22日
    浏览(34)
  • 云计算day07-Docker容器_execstart= usr bin dockerd

    3.2 bridge(桥接式网络)(默认) 启动容器时,首先会在主机上创建一个docker0的虚拟网桥,相当于交换机,同时自动分配一对网卡设备,一半在容器(eth0),一半在宿主机,并且还关联到了docker0,从而进行连接。 每创建一个容器启动时自动分配地址以后会生成iptables规则,ip

    2024年04月25日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包