k8s基于kubeadm部署集群 含集群NotReady解决方案

2023-05-16

1)简介

kubernetes简称k8s。是用于自动部署,扩展和管理容器化应用程序的开源系统。
中文官网:https://kubernetes.io/Zh/
中文社区:https://www.kubernetes.org.cn/
官方文档:https://kubernetes.io/zh/docs/home/
社区文档:https://docs.kubernetes.org.cn/

(2)主机分配

一主二从,centos7.6版本,kubectl1.7.3

(3)设置Linux环境(三个节点都执行)

  • 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
  • 关闭Linux
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
  • 关闭swap
swapoff -a #临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久关闭
free -g #验证,swap必须为0
  • 添加主机名与IP对应关系:

查看主机名:

hostname

hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
hostnamectl set-hostname k8s-node3

如果主机名不正确,可以通过“hostnamectl set-hostname <newhostname> :指定新的hostname”命令来进行修改。

cat >> /etc/hosts << EOF
172.16.1.67 k8s-node3
172.16.1.68 k8s-node2
172.16.1.62 k8s-node1
EOF

将桥接的IPV4流量传递到iptables的链:

cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

应用规则:

sysctl --system

疑难问题:遇见提示是只读的文件系统,运行如下命令

mount -o remount rw /
  • date 查看时间(可选)
yum -y install ntpupdate

ntpupdate time.window.com #同步最新时间

(3)所有节点安装docker、kubeadm、kubelet、kubectl

Kubenetes默认CRI(容器运行时)为Docker,因此先安装Docker。

(1)Doker 安装

清理已经安装的docker(如果没有安装过,可以跳过此步)
yum remove docker \
    docker-client \                  
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-selinux \
    docker-engine-selinux \
    docker-engine
安装Device Mapper工具
yum install -y yum-utils device-mapper-persistent-data lvm2
配置docker的yum数据源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新 yum缓存
yum makecache fast
安装docker-ce(社区版)
yum -y install docker-ce docker-ce-cli containerd.io 
启动docker
systemctl start docker
开机启动
systemctl enable docker.service
重启
systemctl restart docker
启动后可以使用如下命令进行校验
 docker -v

(2)添加阿里与Yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

更多详情见: https://developer.aliyun.com/mirror/kubernetes

(3)安装kubeadm,kubelet和kubectl

yum list|grep kube

安装

yum install -y kubelet-1.17.3 kubeadm-1.17.3 kubectl-1.17.3

开机启动

systemctl enable kubelet && systemctl start kubelet

查看kubelet的状态: 状态是失败,但是在运行是正常的,只要组网后就会显示成功

systemctl status kubelet

查看kubelet版本:

[root@k8s-node2 ~]# kubelet --version
Kubernetes v1.17.3

4)部署k8s-master

(1)master节点初始化

在Master节点上,创建并执行master_images.sh

#!/bin/bash

images=(
	kube-apiserver:v1.17.3
    kube-proxy:v1.17.3
	kube-controller-manager:v1.17.3
	kube-scheduler:v1.17.3
	coredns:1.6.5
	etcd:3.4.3-0
    pause:3.1
)

for imageName in ${images[@]} ; do
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
#   docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName  k8s.gcr.io/$imageName
done

初始化kubeadm

kubeadm init \
--apiserver-advertise-address=172.16.1.62 \
--image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version   v1.17.3 \
--service-cidr=10.96.0.0/16  \
--pod-network-cidr=10.244.0.0/16

注:–apiserver-advertise-address=172.16.1.62 :这里的IP地址是master主机的地址,为上面的eth0网卡的地址;

执行结果:

[root@k8s-node1 opt]# kubeadm init \
> --apiserver-advertise-address=172.16.1.62 \
> --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
> --kubernetes-version   v1.17.3 \
> --service-cidr=10.96.0.0/16  \
> --pod-network-cidr=10.244.0.0/16
W0503 14:07:12.594252   10124 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.17.3
[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[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'
[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
[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-node1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.0.2.15]
[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-node1 localhost] and IPs [10.0.2.15 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-node1 localhost] and IPs [10.0.2.15 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
[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"
W0503 14:07:30.908642   10124 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[control-plane] Creating static Pod manifest for "kube-scheduler"
W0503 14:07:30.911330   10124 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[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 22.506521 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.18" 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 k8s-node1 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node k8s-node1 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: sg47f3.4asffoi6ijb8ljhq
[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
#表示kubernetes已经初始化成功了
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

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.0.2.15:6443 --token sg47f3.4asffoi6ijb8ljhq \
    --discovery-token-ca-cert-hash sha256:81fccdd29970cbc1b7dc7f171ac0234d53825bdf9b05428fc9e6767436991bfb 
[root@k8s-node1 opt]# 

由于默认拉取镜像地址k8s.cr.io国内无法访问,这里指定阿里云仓库地址。可以手动按照我们的images.sh先拉取镜像。

地址变为:registry.aliyuncs.com/googole_containers也可以。
科普:无类别域间路由(Classless Inter-Domain Routing 、CIDR)是一个用于给用户分配IP地址以及在互联网上有效第路由IP数据包的对IP地址进行归类的方法。
拉取可能失败,需要下载镜像。

运行完成提前复制:加入集群的令牌。

(2)测试Kubectl(主节点执行)

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

详细部署文档:https://kubernetes.io/docs/concepts/cluster-administration/addons/

$ kubectl get nodes #获取所有节点

目前Master状态为notready。等第七步组网,网络加入完成即可。

$ journalctl -u kubelet #查看kubelet日志

(5)安装POD网络插件(CNI)

在master节点上执行按照POD网络插件

kubectl apply -f \
https://raw.githubusercontent.com/coreos/flanne/master/Documentation/kube-flannel.yml
[root@k8s-node1 k8s]# kubectl apply -f  kube-flannel.yml    
podsecuritypolicy.policy/psp.flannel.unprivileged 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-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created
[root@k8s-node1 k8s]#

同时flannel.yml中指定的images访问不到可以去docker hub找一个wget yml地址
vi 修改yml 所有amd64的地址修改了即可
等待大约3分钟
查看指定名称空间的pods

kubectl get pods -n kube-system 

查看所有名称空间的pods

kubectl get pods --all-namespaces

执行watch kubectl get pod -n kube-system -o wide 监控pod进度,等待3-10分钟,完全都是running以后继续

查看命名空间:

[root@k8s-node1 k8s]# kubectl get ns
NAME              STATUS   AGE
default           Active   30m
kube-node-lease   Active   30m
kube-public       Active   30m
kube-system       Active   30m
[root@k8s-node1 k8s]#
[root@k8s-node1 k8s]# kubectl get pods --all-namespaces       
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
# coredns 在主节点ready之后会调度成功
kube-system   coredns-546565776c-9sbmk            0/1     Pending   0          31m
kube-system   coredns-546565776c-t68mr            0/1     Pending   0          31m
kube-system   etcd-k8s-node1                      1/1     Running   0          31m
kube-system   kube-apiserver-k8s-node1            1/1     Running   0          31m
kube-system   kube-controller-manager-k8s-node1   1/1     Running   0          31m
kube-system   kube-flannel-ds-amd64-6xwth         1/1     Running   0          2m50s
kube-system   kube-proxy-sz2vz                    1/1     Running   0          31m
kube-system   kube-scheduler-k8s-node1            1/1     Running   0          31m

查看master上的节点信息:

[root@k8s-node1 k8s]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
k8s-node1   NotReady    master   34m   v1.17.3 

如果master一直没有ready,查看日志报错:[failed to find plugin “flannel” in path [/opt/cni/bin]]

解决结点NotReady方案

github下载地址:https://github.com/containernetworking/plugins/releases/tag/v0.8.6

下载后上传到Linux /k8s目录解压

tar zxvf cni-plugins-linux-amd64-v0.8.6.tgz

复制 flannel 到 /opt/cni/bin/

cp flannel /opt/cni/bin/

再查看状态

[root@k8s-node1 k8s]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
k8s-node1   NotReady    master   34m   v1.17.3   #status为ready才能够执行下面的命令

最后再次执行,并且分别在“k8s-node2”和“k8s-node3”上也执行这里命令:

# 请使用当时生成的token,不要复制这个
kubeadm join 172.16.1.62:6443 --token zy7rjn.60c64bs6a9fiiw8n     --discovery-token-ca-cert-hash sha256:73cb3ebfdee05b40824c93e6ec470b5eeff128c0bdab433bfe720f8050ded1aa 
# 如果没记录token,在主节点执行:
kubeadm token create --print-join-command
[root@k8s-node1 opt]# kubectl get nodes
NAME        STATUS     ROLES    AGE   VERSION
k8s-node1   Ready      master   47m   v1.17.3
k8s-node2   NotReady   <none>   75s   v1.17.3
k8s-node3   NotReady   <none>   76s   v1.17.3

监控pod进度

watch kubectl get pod -n kube-system -o wide

如果监控状态都running了,但是从节点没有ready

1、在从节点查看日志

[root@k8s-node2 ~]# journalctl -u kubelet -f

2、如果是: [failed to find plugin “flannel” in path [/opt/cni/bin]], 则和前面master一样解决

[root@k8s-node1 ~]#  kubectl get nodes;                         
NAME        STATUS   ROLES    AGE     VERSION
k8s-node1   Ready    master   3h50m   v1.17.3
k8s-node2   Ready    <none>   3h3m    v1.17.3
k8s-node3   Ready    <none>   3h3m    v1.17.3
[root@k8s-node1 ~]# 

(6)加入kubenetes的Node节点

token过期怎么办

kubeadm token create --print-join-command
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

k8s基于kubeadm部署集群 含集群NotReady解决方案 的相关文章

随机推荐

  • 总结:数据清洗的一些总结

    前言 在整理项目的时候发现清洗过程是一个非常细节的过程 xff0c 几乎贯穿始终 xff0c 也是后续步骤特征提取等的前置条件 xff0c 所以整理如下 因为展开较大 xff0c 所以我已近上传mindnode脑图和原始照片尺寸 xff0c
  • Ubuntu18.04+Melodic+UR5

    文章目录 配置与使用文件内容ur gazebo ur5 ROS Gazebo pickup 配置与使用 https github com ros industrial universal robot有详细说明 用Gazebo roslaun
  • cuda10.0 安装torch1.7.1

    pip install torch1 7 1 43 cu92 torchvision0 8 2 43 cu92 torchaudio 61 61 0 7 2 f https download pytorch org whl torch st
  • 对抗训练

    文章目录 1 定义2 对抗训练 xff1a 从CV到NLP2 1 CV中的数据格式2 2 NLP中数据格式 xff13 对抗样本与数据增强样本 xff14 如何确定微小扰动 xff14 1 Fast Gradient Sign Method
  • 38、带参数的装饰器

    一 带参数的装饰器 我们看 xff0c 装饰器其实就是一个闭包函数 xff0c 再说简单点就是两层的函数 那么是函数 xff0c 就应该具有函数传参功能 login status 61 39 username 39 None 39 stat
  • Git系列:windows10安装Git版本控制工具!

    Git系列 xff1a windows10安装Git版本控制工具 xff01 前言 今天博主将为大家分享Git系列 xff1a windows10安装Git版本控制工具 xff01 不喜勿喷 xff0c 如有异议欢迎讨论 xff01 开始安
  • VNC 连接腾讯云服务器(解决黑屏、灰屏问题)

    整了一天 xff0c 要么黑屏 xff0c 要么灰屏 xff0c 巴拉巴拉 xff0c 最后终于好了 vnc xstartup修改为如下 随后chmod 777 vnc xstartup 就可以了 教程视屏 xff1a https clou
  • 【云计算学习笔记(二十一)】之Neutron子服务详细介绍

    文章目录 本文章由公号 开发小鸽 发布 xff01 欢迎关注 xff01 xff01 xff01 一 xff0e Neutron xff08 一 xff09 Neutron介绍 xff08 二 xff09 Neutron功能1 二层交换Sw
  • 51单片机、DS18B20、智能窗帘控制系统

    写在最前面 xff1a 文章是我的设计报告搬运过来的 xff0c 嫌排版乱的 xff0c 可以直接下载设计报告 xff0c 包含word xff0c keil工程 xff0c proteus工程 xff01 xff01 xff01 xff0
  • 手写RTOS-PendSV中断

    今天这一篇 xff0c 我们说一下操作系统都要用到的PendSV中断 xff0c 整个操作系统中 xff0c 要自己写的的汇编代码不超过20行 xff0c 全部都在PendSV中断里 以下是 Cotex M3权威指南 里对PendSV的描述
  • 如何知道可执行文件是32-bit还是64-bit

    可以使用GetBinaryType API来获得这个信息 xff1a BOOL GetBinaryType LPCTSTR lpApplicationName LPDWORD lpBinaryType Binary Type可以是下面的值
  • 手写RTOS-使用PendSV进行压栈与出栈操作

    学会使用PendSV中断进行压栈和出栈操作 xff0c 是实现任务调度的关键 今天我们就来学习一下如何使用不超过20行的汇编实现压栈和出栈操作 我们现在来实现这么一个例子 xff1a 先把R4 R11通用寄存器的值保存到一个缓冲区里面 xf
  • 树莓派 Ubuntu mate 16.04 下开启vncserver完整教程

    关于开启vncserver的教程 xff0c 在树莓派上不桶系统上 xff0c 有很多教程 xff0c 杂七杂八 这里的环境是 xff1a 树莓派3b 43 Ubuntu 16 04 mate 一 xff1a 在树莓派下完成以下任务 1 安
  • 在linux上安装oracle数据库并通过远程映射建库

    前期准备 安装虚拟机 xff1a 我这里用的VM15 5 xff0c 可用虚拟机有CentOS以及红帽系列版本下载oracle数据库的安装包以及 rpm补丁包 xff0c 并传入linux虚拟机 xff1a 在虚拟机安装VMTools以共享
  • VMware虚拟机Ubuntu无法连接网络的解决办法

    原文来源 1 Ubuntu网络设置 xff1a 依次单击 System Settings gt Network gt Wired gt Options xff0c 如下图所示 xff1a 依次选择 General xff0c 勾选如下图所示
  • Meta-Learning之How to train your MAML

    这篇文章是MAML的升级版本 xff0c 即MAML 43 43 他针对MAML的一些不足之处做了对应的改进 xff0c 如稳定性 收敛速度 表现力等均得到提升 由于自己的算法实现中有用到MAML xff0c 为了让整体算法有一个好的性能
  • 对于中断的笔记

    我们首先要区分内核与外设 内核是为众多应用程序提供对硬件的安全访问的软件芯片 xff0c 如Cortex M4 xff0c 是ARM公司开发的 外设是ST公司在拿到这个内核后 xff0c 制作了相应的硬件 xff0c 如GPIO RTC以及
  • 正则表达式中?=和?:和?!的理解

    要理解 61 和 xff0c 首先需要理解前瞻 xff0c 后顾 xff0c 负前瞻 xff0c 负后顾四个概念 xff1a 前瞻 xff1a exp1 61 exp2 exp1后边是exp2就匹配 后顾 xff1a lt 61 exp2
  • JAVA中的向上转型和向下转型

    一 向上转型和向下转型 向上转型和向下转型是在JAVA继承操作中用到的东西 xff0c 在讲到转型之前我们需要认识到继承过程中的对象类型转换 xff0c 这种转换有两个特点 xff1a 1 这是继承过程中发生的操作 2 新类是现有类的一种类
  • k8s基于kubeadm部署集群 含集群NotReady解决方案

    1 xff09 简介 kubernetes简称k8s 是用于自动部署 xff0c 扩展和管理容器化应用程序的开源系统 中文官网 xff1a https kubernetes io Zh 中文社区 xff1a https www kubern