linux 使用kubeadm安装部署K8S

news/2024/7/8 0:39:03

上一节,安装了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


http://lihuaxi.xjx100.cn/news/2125456.html

相关文章

【MySQL】聊聊自增id用完怎么办?

在实际的开发中,一般都会将数据存储到数据库中,在设计表的时候,其实id如果达到最大值的话,会出现什么问题。其实主要分两种情况,一种是设置了主键id,另一种没有设置主键id。 表定义自增值id create table…

【蓝桥杯】tarjan算法

一.概述 Tarjan 算法是基于DFS的算法,用于求解图的连通性问题。 Tarjan 算法可以在线性时间内求出: 无向图: 割点与桥双连通分量 有向图: 强连通分量必经点与必经边 1.割点: 若从图中删除节点 x 以及所有与 x 关联的…

【机器学习】原理+实例, 一文掌握 精确率、召回率与F1分数,再也不迷路。

精确率、召回率与F1分数 1、引言2、定义2.1 精确率2.2 召回率2.3 F1分数2.4 二分类任务2.5 代码示例 3、总结 1、引言 小屌丝:鱼哥,你在给我详细的唠叨唠叨 精确率,召回率和F1分数。 小鱼:这…这不是机器学习基本知识吗 小屌丝&a…

Tomcat 下载以及安装

Tomcat安装及配置教程主要分为四步: 步骤一:首先确认自己是否已经安装JDK 1. cmd:查看java的版本 步骤二:下载安装Tomcat 1. 下载tomcat :Apache Tomcat - Welcome! 2. 选择对应的tomcat版本: 3. 进行安装&#…

【数据分享】1929-2023年全球站点的逐日平均压力(Shp\Excel\免费获取)

气象数据是在各项研究中都经常使用的数据,气象指标包括气温、风速、降水、能见度等指标,说到气象数据,最详细的气象数据是具体到气象监测站点的数据! 有关气象指标的监测站点数据,之前我们分享过1929-2023年全球气象站…

前后端实时数据通信

实现前后端实时数据转换通常涉及到以下几个步骤: 后端提供数据转换接口。 前端实时数据获取。 前端实时数据转换。 前端实时展示转换后数据。 以下是一个简单的例子,假设后端提供了一个接口来转换某种数据格式,前端使用JavaScript和WebS…

Redis缓存预热,该如何实现

一、什么是缓存预热 缓存预热是一种在程序启动或缓存失效之后,主动将热点数据加载到缓存中的策略。这样,在实际请求到达程序时,热点数据已经存在于缓存中,从而减少了缓存穿透和缓存击穿的情况,也缓解了SQL服务器的压力…

node-fs(fileSystem)文件系统-write--02

1.简介 实现与硬盘的交互,文件创建,删除与重命名,移动以及文件内容的写入与读取以及文件夹相关操作。 2.fs 模块的常见用法 2.1fs.writeFile() 方法用于异步地将数据写入文件。 新建一个文件xxx.txt 写入内容 哟哟 实际应用场景&#xff0c…