Kubernetes 安装

首先,请参考以下网站:
https://www.server-world.info/query?os=CentOS_7&p=kubernetes

下面的网站是参考资料:https://qiita.com/yasubehe/items/51a05688d1f66d51531e

Docker的版本

[root@kube1 ~]# docker version
Client: Docker Engine - Community
 Version:           24.0.6
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:33:07 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.6
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       1a79695
  Built:            Mon Sep  4 12:32:10 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0

执行kubeadm init时出现以下错误内容

我认为这个错误与②有关。

  [ERROR CRI]: container runtime is not running: output: time="2023-08-14T04:20:42-04:00" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"

在 `/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf` 文件中需要修正的部分除外。

在所有通过Pod部署的地方进行修正。

10-kubeadm.conf是一个文件名。

打开 `/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf` 文件,并追加以下内容:`–cgroup-driver=systemd`。

 

当选择systemd作为初始化系统时,缓解这种不稳定性的方法是将systemd作为kubelet和容器运行时的cgroup驱动程序。

当选择systemd作为init系统时,减轻这种不稳定性的方法是在cgroup driver(kubelet和容器运行时,这里指的是docker)中使用systemd。

原因:
systemd与cgroups紧密集成,为每个systemd单元分配一个cgroup。因此,如果您在cgroupfs驱动程序中使用systemd作为初始化系统,则系统会得到两个不同的cgroup管理器。

系统中存在两个不同的cgroup管理器。

为了避免分配资源给两个存在的cgroups,需要进行上述设置。

因为存在两个cgroups,将会有两个用于管理资源的进程。

最终导致系统变得不稳定。

ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS --cgroup-driver=systemd

之后,
systemctl 重新加载守护程序
systemctl 停止 kubelet
systemctl 启动 kubelet

对config.toml进行修改。

用哪个容器运行时来运行的来着来着?

 

/etc/containerd/config.toml
添加注释

#disabled_plugins = ["cri"]

关闭containerd的systemctl命令为:systemctl stop containerd。
启动containerd的systemctl命令为:systemctl start containerd。

你想要哪种口红颜色?

在进行之前,请确认当前的设置。

以下是原文的中文同义词替换:

docker版本
docker信息 | grep -i 驱动程序

 

以下是一个选项的汉语译文:《/etc/docker/daemon.json》[链接](https://devlights.hatenablog.com/entry/2021/11/30/010150)。

{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}

重载守护进程: systemctl daemon-reload
重新启动Docker:systemctl restart docker

执行kubeadm init

[root@kube1 ~]# kubeadm init --apiserver-advertise-address=192.168.2.81 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.28.2
[preflight] Running pre-flight checks
        [WARNING FileExisting-tc]: tc not found in system path
        [WARNING Hostname]: hostname "kube1" could not be reached
        [WARNING Hostname]: hostname "kube1": lookup kube1 on 192.168.2.1:53: no such host
[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'
W1009 01:06:41.183364   12410 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image.
[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 [kube1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.2.81]
[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 [kube1 localhost] and IPs [192.168.2.81 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [kube1 localhost] and IPs [192.168.2.81 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
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[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"
[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
[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 6.001106 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] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node kube1 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 kube1 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: h0z32j.wzk0u4svj3atjyvc
[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/

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

kubeadm join 192.168.2.81:6443 --token h0z32j.wzk0u4svj3atjyvc \
        --discovery-token-ca-cert-hash sha256:667c7930cc45f64fd3733b833501121d5e896714cc48a453e79099bbeb07b70c
[root@kube1 ~]#

可以知道运行在哪个容器运行时上。


[root@kube1 ~]# kubectl get nodes -o wide
NAME    STATUS     ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE          KERNEL-VERSION          CONTAINER-RUNTIME
kube1   Ready      control-plane   55d   v1.28.2   192.168.2.81   <none>        CentOS Stream 8   4.18.0-326.el8.x86_64   containerd://1.6.24
kube2   NotReady   <none>          55d   v1.28.2   192.168.2.82   <none>        CentOS Stream 8   4.18.0-326.el8.x86_64   containerd://1.6.24
kube3   Ready      <none>          55d   v1.28.2   192.168.2.83   <none>        CentOS Stream 8   4.18.0-326.el8.x86_64   containerd://1.6.24

bannerAds