上一节,安装了docker-20.10.14版本

安装kubeadm,kubelet和kubectl

由于版本更新频繁,这里指定版本号部署

 yum  install kubelet-1.23.4-0 kubeadm-1.23.4-0 kubectl-1.23.4-0 -y
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package kubeadm.x86_64 0:1.23.4-0 will be installed
--> Processing Dependency: kubernetes-cni >= 0.8.6 for package: kubeadm-1.23.4-0.x86_64
---> Package kubectl.x86_64 0:1.23.4-0 will be installed
---> Package kubelet.x86_64 0:1.23.4-0 will be installed
--> Running transaction check
---> Package kubernetes-cni.x86_64 0:1.2.0-0 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                        Arch                   Version                    Repository                  Size
===================================================================================================================
Installing:
 kubeadm                        x86_64                 1.23.4-0                   kubernetes                 9.0 M
 kubectl                        x86_64                 1.23.4-0                   kubernetes                 9.5 M
 kubelet                        x86_64                 1.23.4-0                   kubernetes                  21 M
Installing for dependencies:
 kubernetes-cni                 x86_64                 1.2.0-0                    kubernetes                  17 M

Transaction Summary
===================================================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 56 M
Installed size: 255 M
Downloading packages:
(1/4): c8a17896ac2f24c43770d837f9f751acf161d6c33694b5dad42f5f638c6dd626-kubeadm-1.23.4-0.x8 | 9.0 MB  00:00:20     
(2/4): ae22dad233f0617861909955e30f527067e6f5535c1d1a9cda7b3a288fe62cd2-kubectl-1.23.4-0.x8 | 9.5 MB  00:00:20     
(3/4): 7a0d50ba594f62deddd266db3400d40a3b7 92% [==============================   ] 892 kB/s |  52 MB  00:00:05 ETA 
(3/4): 0f2a2afd740d476ad77c508847bad1f559afc2425816c1f2ce4432a62dfe0b9d-kubernetes-cni-1.2. |  17 MB  00:00:38     
(4/4): 7a0d50ba594f62deddd266db3400d40a3b745be71f10684faa9c1632aca50d6b-kubelet-1.23.4-0.x8 |  21 MB  00:00:47     
-------------------------------------------------------------------------------------------------------------------
Total                                                                              845 kB/s |  56 MB  00:01:07     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kubelet-1.23.4-0.x86_64                                                                         1/4 
  Installing : kubernetes-cni-1.2.0-0.x86_64                                                                   2/4 
  Installing : kubectl-1.23.4-0.x86_64                                                                         3/4 
  Installing : kubeadm-1.23.4-0.x86_64                                                                         4/4 
  Verifying  : kubeadm-1.23.4-0.x86_64                                                                         1/4 
  Verifying  : kubernetes-cni-1.2.0-0.x86_64                                                                   2/4 
  Verifying  : kubelet-1.23.4-0.x86_64                                                                         3/4 
  Verifying  : kubectl-1.23.4-0.x86_64                                                                         4/4 

Installed:
  kubeadm.x86_64 0:1.23.4-0             kubectl.x86_64 0:1.23.4-0             kubelet.x86_64 0:1.23.4-0            

Dependency Installed:
  kubernetes-cni.x86_64 0:1.2.0-0                                                                                  

Complete!

启动kubelet

# systemctl start kubelet
[root@host-10-19-83-151 docker]# systemctl status  kubelet.service 
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: activating (auto-restart) (Result: exit-code) since Tue 2024-03-26 16:37:12 CST; 8s ago
     Docs: https://kubernetes.io/docs/
  Process: 8613 ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=1/FAILURE)
 Main PID: 8613 (code=exited, status=1/FAILURE)

Mar 26 16:37:12 host-10-19-83-151 systemd[1]: Unit kubelet.service entered failed state.
Mar 26 16:37:12 host-10-19-83-151 systemd[1]: kubelet.service failed.

查看日志journalctl -xe

Failed to load kubelet config file" err="failed to load Kubelet config file /var/lib/kubelet/config.yaml, error failed to read kubelet config file \"/var/lib/kubelet/config.yaml\"

原因是这台机器,原来有过kubernutes环境,需要环境初始化

#  kubeadm init \
>  --apiserver-advertise-address=10.18.18.18 \
>  --image-repository registry.aliyuncs.com/google_containers \
>  --kubernetes-version v1.23.4 \
>  --service-cidr=10.96.0.0/12 \
>  --pod-network-cidr=10.244.0.0/16 \
>  --ignore-preflight-errors=all
[init] Using Kubernetes version: v1.23.4
[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 [host-10-19-83-151 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.19.83.151]
[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 [host-10-19-83-151 localhost] and IPs [10.19.83.151 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [host-10-19-83-151 localhost] and IPs [10.19.83.151 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 34.003860 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
NOTE: The "kubelet-config-1.23" naming of the kubelet ConfigMap is deprecated. Once the UnversionedKubeletConfigMap feature gate graduates to Beta the default name will become just "kubelet-config". Kubeadm upgrade will handle this transition transparently.
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node host-10-19-83-151 as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node host-10-19-83-151 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: q4r3j6.w1ilfk5gal5z6e9n
[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 10.18.18.18:6443 --token q4r3j6.w133333333z6e9n \
        --discovery-token-ca-cert-hash sha256:c3580c9a2903e42222222222222222222289a469ef60b85de260015f180690a129

初始化就是成功的。

查看node状态,是notReady

# kubectl get nodes
NAME                STATUS     ROLES                  AGE     VERSION
host-10-19-83-151   NotReady   control-plane,master   6m42s   v1.23.4

安装网络插件

# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
namespace/kube-flannel created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created

kubelet运行正常

# systemctl status kubelet.service 
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Tue 2024-03-26 16:52:52 CST; 1min 50s ago
     Docs: https://kubernetes.io/docs/
 Main PID: 11727 (kubelet)
    Tasks: 19
   Memory: 34.0M
   CGroup: /system.slice/kubelet.service
           └─11727 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/...

Mar 26 16:54:18 host-10-19-83-151 kubelet[11727]: E0326 16:54:18.695760   11727 kubelet.go:2347] "Container ...zed"
Mar 26 16:54:22 host-10-19-83-151 kubelet[11727]: I0326 16:54:22.926785   11727 cni.go:240] "Unable to updat...t.d"
Mar 26 16:54:23 host-10-19-83-151 kubelet[11727]: E0326 16:54:23.718069   11727 kubelet.go:2347] "Container ...zed"
Mar 26 16:54:27 host-10-19-83-151 kubelet[11727]: I0326 16:54:27.927646   11727 cni.go:240] "Unable to updat...t.d"
Mar 26 16:54:28 host-10-19-83-151 kubelet[11727]: E0326 16:54:28.739272   11727 kubelet.go:2347] "Container ...zed"
Mar 26 16:54:32 host-10-19-83-151 kubelet[11727]: I0326 16:54:32.928423   11727 cni.go:240] "Unable to updat...t.d"
Mar 26 16:54:33 host-10-19-83-151 kubelet[11727]: E0326 16:54:33.765686   11727 kubelet.go:2347] "Container ...zed"
Mar 26 16:54:37 host-10-19-83-151 kubelet[11727]: I0326 16:54:37.928958   11727 cni.go:240] "Unable to updat...t.d"
Mar 26 16:54:38 host-10-19-83-151 kubelet[11727]: E0326 16:54:38.784954   11727 kubelet.go:2347] "Container ...zed"
Mar 26 16:54:42 host-10-19-83-151 kubelet[11727]: I0326 16:54:42.929909   11727 cni.go:240] "Unable to updat...t.d"
Hint: Some lines were ellipsized, use -l to show in full.

查看k8s环境

kubectl get nodes
NAME                STATUS   ROLES                  AGE   VERSION
host-10-10-10-10    Ready    control-plane,master   22m   v1.23.4
 
[root@host-10-10-10-10 yum.repos.d]# kubectl get po -A 
NAMESPACE      NAME                                        READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-lpm9c                       1/1     Running   0          16m
kube-system    coredns-6d8c4cb4d-sml87                     1/1     Running   0          22m
kube-system    coredns-6d8c4cb4d-w4hgz                     1/1     Running   0          22m
kube-system    etcd-host-10-10-10-10                       1/1     Running   160        22m
kube-system    kube-apiserver-host-10-10-10-10             1/1     Running   0          22m
kube-system    kube-controller-manager-host-10-10-10-10    1/1     Running   0          22m
kube-system    kube-proxy-6ct9f                            1/1     Running   0          22m
kube-system    kube-scheduler-host-10-19-83-151            1/1     Running   3024       22m

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐