当前位置: 首页 > news >正文

K8S部署及常见问题处理

目录

k8s kubeadm 一键自动化,安装k8s集群,安装所有运行需要的组件

一、环境初始化(三台机器都需要执行)

主机名、节点ip、部署组件

1、配置hosts(主节点master和业务节点node都需要配置)文件内容

2、配置主节点master和业务节点node中的hostname

3、配置网络后查看网络是否能通

4、设置安全开放端口

5、设置iptables(初始化防火墙)(可以写成脚本)

6、关闭swap

7、配置yum源(阿里云源)(可以写成脚本)

8、ntp配置(同步网络)(可以写成脚本)

9、修改linux内核参数,开启数据包转发功能

10、安装docker基础环境(安装docker 脚本)

11、安装k8s的初始化工具kubeadm命令 (所有节点执行)

12、所有机器执行

13、k8s安装完毕之后,设置所有节点的kubelet开机启动运行,该工具用于建立起K8S集群,master,node之间的联系

15、先保留所有节点的应用 端口状态,之后可以看k8s跑起来之后,占用了哪些端口,知道哪些程序运行了

二、初始化k8s-master 主节点(只在主节点执行)

1、执行kubeadm init初始化,加入参数如下:

2、在master主节点需要执行:

3、将node节点加入到master集群

4、查看6443端口

三、配置k8s命令补全

四、 部署网络插件

1.下载网络插件,配置文件 ,yam1以及配置文件

2.在k8s主节点上,应用这个yam1,基于yam1,创建具体的pod过程

3.如果需要修改pod运行网络,要改配置文件(此路径为下载下来的flannel 解压下来的flannel路径下的 kube-flannel.yml)

3.1.需要修改的第一处Network

3.2.需要修改的第二处

3.3、报错处理

3.4、查看当前master容器中是否已经运行了flannel

3.5、运行kubectl get nodes -owide

五、部署pod

5、创建空间,创建pod,部署pod

六、将删除原来的node重新添加到master控制器集群

1、查看需要加入master集群的命令

 2、使用kubeadm reset  将需要添加的node 重置。

3、重新添加node节点到master

七、常见问题及处理

1、问题一:创建pod 出现了状态为0

1.1 解决方法:

1.1、处理方法一

1.1.1、在master和node上都创建subnet.env这个文件

1.2、处理方法二

1.3、处理方法三

1.4、处理方法四

1.4.1、查看开启scheduler, control-manager的10251,10252端口是否正常



k8s kubeadm 一键自动化,安装k8s集群,安装所有运行需要的组件

k8s-master 192.168.150.112 etcd, kube-apiserver, kube-controller-manager, kubectl,kubeadm, kubelet, kube-proxy, flannel

k8s-node1 192.168.150.113 kubectl, kubelet, kube-proxy, flannel,docker

k8s-node2 192.168.150.114 kubectl, kubelet, kube-proxy, flannel,docker

确保三台机器的跨节点容器互相通信,装网络插件flannel

K8S部署步骤如下:


一、环境初始化(三台机器都需要执行)

主机名、节点ip、部署组件

1、配置hosts(主节点master和业务节点node都需要配置)文件内容

cat >>/etc/hosts <<EOF
192.168.150.112 master01
192.168.150.113 node01
192.168.150.114 node02
EOF

2、配置主节点master和业务节点node中的hostname

每个节点都需要单独配置如下

每个节点都需要单独配置
节点master01node01node02
路径vi    /etc/hostnamevi    /etc/hostnamevi    /etc/hostname
内容master01node01node02

3、配置网络后查看网络是否能通

ping -c 2 k8s-master-10
ping -c 2 k8s-node-11
ping -c 2 k8s-node-12

4、设置安全开放端口

如果是ESC机器需要开放端口,如果是虚拟机部署不需要开放端口,虚拟机默认已经打开;

5、设置iptables(初始化防火墙)(可以写成脚本)

systemctl stop firewalld NetworkManagersystemctl disable firewalld NetworkManagersed -ri  's#(SELINUX=).*#\disabled#' /etc/selinux/configsetenforce 0systemctl disable firewalld 8& systemctl stop firewalldgetenforce  0
iptables -F
iptables -X
iptables -Z
iptables -P FORWARD ACCEPT

6、关闭swap

k8s默认禁用swap功能 

swapoff -a

防止开机自动挂载 swap 分区

sed -i  '/swap/ s/^\(.*\)$/#\1/g'  /etc/fstab

7、配置yum源(阿里云源)(可以写成脚本)

curl  -o  /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repocurl -o  /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.reposed -i  '/aliyuncs/d'    /etc/yum.repos.d/*.repoyum clean all && yum makecache fast

8、ntp配置(同步网络)(可以写成脚本)

yum install chrony -ysystemctl start chronyd
systemctl enable chronyddatehwclock -w

9、修改linux内核参数,开启数据包转发功能

##容器夸主机通通信,底层是走的iptables,内核级别的数据包转发
cat <<EOF> /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables =1
net.ipv4.ip_forward=1
vm.max_map_count=262144
EOFmodprobe br_netfilter
##加载读取内核参数配置文件
sysctl -p /etc/sysctl.d/k8s.conf

10、安装docker基础环境(安装docker 脚本)

yum remove docker docker-common docker-selinux docker-engine -y
curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce --showduplicates
yum install docker-ce-19.03.15 docker-ce-cli-19.03.15 -y
##配置docker加速器、以及crgoup驱动,改为k8s官方推荐的systemd,否则初始化时会有报错。
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<'EOF'
{"exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts": {"max-size": "100m"},"storage-driver": "overlay2"
}
EOF#启动
systemctl start docker 8& systemctl enable docker
docker version

11、安装k8s的初始化工具kubeadm命令 (所有节点执行)

#安装k8s集群环境初始化的工具 kubelet-1.19.3 # 组件,增制改查pod再具体机器上,pod可以运行主节点上,node节点上 kubeadm-1.19.3 # k8s版本 1.19.3 ,自动拉去k8s基础组件镜像的一个工具 kubect1-1.19.3 # 管理I 维护k8s客户端换,和服务端交互的一个命令行工具kubect1-1.19.3

12、所有机器执行

##设置阿里云源,安装kubadm工具(脚本)

curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors,aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repocat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOFyum clean all && yum makecache  
##yum list kubeadm --showduplicates   列出阿里云有哪些K8S版本;
##安装的kubeadm版本,就是决定了,拉去什么版本的k8s集群版本的# 安装指定版本 kubeadm-1.19.3镜像,
yum install kubelet-1.19.3 kubeadm-1.19.3  kubectl-1.19.3 ipvsadm  -y

13、k8s安装完毕之后,设置所有节点的kubelet开机启动运行,该工具用于建立起K8S集群,master,node之间的联系

##查看kubeadm 版本,初始化k8s版本信息v1.19.3

kubeadm version

[root@k8s-master-10 ~]#kubeadm version

kubeadm version: &version.InfofMajor:"1", Minor:"19" Gitversion:"v1.19.3"GitCommit;"1e11e4a2108024935ecfcb2912226cedeafd99df",GitTreeState:"clean"BuildDate:“2020-16-14T12:47:53Z",Go

##设置kubelet开机启动

 systemctl enable kubeletsystemctl enable docker

15、先保留所有节点的应用 端口状态,之后可以看k8s跑起来之后,占用了哪些端口,知道哪些程序运行了

netstat -tunlp

三台机器(master,弄得,)初始化结束!!!


二、初始化k8s-master 主节点(只在主节点执行)

1、执行kubeadm init初始化,加入参数如下:

kubeadm init  \
--apiserver-advertise-address=192.168.150.115  \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.19.3  \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=swap 
##--service-dns-domain= cluster.local \# service-cidr和pod-network-cidr需要和其他机器IP不冲突皆可

##注:

##执行报错需要打开/usr/lib/systemd/system/docker.service,将代码Environment="NO_PROXY=127.0.0.1/8, 127.0.0.1/16"  放在[Service] Type=notify的后面,然后重启daemon和docker,然后重启

 sudo systemctl daemon-reloadsudo systemctl restart dockersudo systemctl restart kubelet

执行成功如下图:

执行成功后需要将上图中标记的信息记录下来,下面在部署node节点上执行;

mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configkubeadm join 192.168.150.115:6443 --token nn1lsp.kpy2mprlsaqg1x81 \--discovery-token-ca-cert-hash sha256:a4c00296ddb1ee6640e0a6b106d4977f14301d12c1e05cc44cc81fb5042248a8

2、在master主节点需要执行:

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

##在master节点查看集群信息

kubectl get nodes -owide
[root@master01 etc]# kubectl  get nodes -owide
NAME       STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
master01   Ready    master   57m   v1.19.3   192.168.150.115   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://19.3.15
​

3、将node节点加入到master集群

在两台node节点运行如下命令:

kubeadm join 192.168.150.115:6443 --token nn1lsp.kpy2mprlsaqg1x81 \--discovery-token-ca-cert-hash sha256:a4c00296ddb1ee6640e0a6b106d4977f14301d12c1e05cc44cc81fb5042248a8
[root@node01 hlw]# kubeadm join 192.168.150.115:6443 --token nn1lsp.kpy2mprlsaqg1x81 \
>     --discovery-token-ca-cert-hash sha256:a4c00296ddb1ee6640e0a6b106d4977f14301d12c1e05cc44cc81fb5042248a8 
[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 -oyaml'
[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.

##在master节点查看集群信息

kubectl get nodes -owide
[root@master01 etc]# kubectl  get nodes -owide
NAME       STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master01   Ready    master   71m   v1.19.3   192.168.150.115   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node01     Ready    <none>   95s   v1.19.3   192.168.150.113   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node02     Ready    <none>   90s   v1.19.3   192.168.150.114   <none>        CentOS Linux 7 (Core)   3.10.0-1160.83.1.el7.x86_64   docker://19.3.15
​

4、查看6443端口

##安装过程解析:

执行如下命令参数:
kubeadm init  \
--apiserver-advertise-address=192.168.150.115  \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.19.3  \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=swap [root@master01 ~]# kubeadm init  \
> --apiserver-advertise-address=192.168.150.115  \
> --image-repository registry.aliyuncs.com/google_containers \
> --kubernetes-version v1.19.3  \
> --service-cidr=10.96.0.0/12 \
> --pod-network-cidr=10.244.0.0/16 \
> ##--service-dns-domain= cluster.local \
W0426 10:56:12.149482    7418 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.19.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 [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master01] and IPs [10.96.0.1 192.168.150.115]
[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 [localhost master01] and IPs [192.168.150.115 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master01] and IPs [192.168.150.115 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 18.513092 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.19" 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 master01 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node master01 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: nn1lsp.kpy2mprlsaqg1x81
[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/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config##现在应该将一个pod网络部署到集群。 pod分布再多个机器上,pod互相之间链接部署,集群网络,选用flannel网络播件
安装,使用即可。
运行“kubectl apply -f [podnetwork]”。Yaml”,其中一个选项列在:
https://kubernetes.io/docs/concepts/cluster-administration/addons/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.150.115:6443 --token nn1lsp.kpy2mprlsaqg1x81 \--discovery-token-ca-cert-hash sha256:a4c00296ddb1ee6640e0a6b106d4977f14301d12c1e05cc44cc81fb5042248a8 
[root@master01 ~]#

##kubeadm 参数详解: kubeadm init \ --apiserver-advertise-address=192.168.150.112 \ # api-server运行在k8s-master的ip --image-repository registry.aliyuncs.com/google_containers \ # 拉去k8s镜像,从阿里云上获取,否则默认是国外的k8s镜像地址,下载不了 --kubernetes-version v1.19.3 \ # 和kubeadm保持一致 --service-cidr-10.1.0.8/16 \ # k8s服务发现网段设置,service网段 --pod-network-cidr=10.2.0.0/16 # 设置pod创建后,的运行网段地址 --service-dns-domain=cluster.local \ # k8s服务发现网段设置,service资源的域名后缀 --ignore-preflight-errors=swap \ # 忽略swap报错 --ignore-preflight-errors=NumCPU #忽略cpu数量报错

三、配置k8s命令补全

##k8s命令太多,务必要配置补全

操作节点: k8s-master

yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl corpletion bash)">> ~/.bashrcyum install bash-completion -y
kubectl completion bash >/etc/bash_completion.d/kubectl
echo 'source <(kubectl completion bash)' >>~/.bashrc yum install bash-completion -y
echo 'source <(kubectl completion bash)' >>~/.bashrc 
kubectl completion bash >/etc/bash_completion.d/kubectl

四、 部署网络插件

1.下载网络插件,配置文件 ,yam1以及配置文件

git clone --depth 1 GitHub - flannel-io/flannel: flannel is a network fabric for containers, designed for Kubernetes GitHub - flannel-io/flannel: flannel is a network fabric for containers, designed for Kubernetes

2.在k8s主节点上,应用这个yam1,基于yam1,创建具体的pod过程

3.如果需要修改pod运行网络,要改配置文件(此路径为下载下来的flannel 解压下来的flannel路径下的 kube-flannel.yml)

cd  /usr/local/hlw/flannel-master/Documentation

3.1.需要修改的第一处Network

##查看kube-flannel.yml 中的“Network”配置是否和kubeadm init 中的--pod-network-cidr=10.244.0.0/16 地址保持一致;

grep "Network" -A 5 kube-flannel.yml
[root@master01 Documentation]# grep "Network" -A 5 kube-flannel.yml "Network": "10.244.0.0/16","Backend": {"Type": "vxlan"}}
---
--hostNetwork: truepriorityClassName: system-node-criticaltolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannel

##如果不一样就需要修改"Network"配置

vi /usr/local/hlw/flannel-master/Documentation/kube-flannel.yml

##在kube-flannel.yml里面找到Network (使用命令/Network)

  net-conf.json: |{"Network": "10.244.0.0/16","Backend": {"Type": "vxlan"}}
##"Network": "10.244.0.0/16", 中的配置和kubeadm init 中的--pod-network-cidr=10.244.0.0/16 地址保持一致;

3.2.需要修改的第二处

##如果机器存在多网卡的话,指定内网物理网卡的名称,默认不指定的话会找第一块网卡

cd /usr/local/hlw/flannel-master/Documentation

##在kube-flannel.yml中找到containers 添加- --iface:enp0s3 (enp0s3是提供对外访问的网卡名称)

vi kube-flannel.yml

基于kubect1命令,应用这个ym1文件,读取,以及创建pod资源

kubectl create -f kube-flannel.yml
[root@master01 Documentation]# kubectl create -f ./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

3.3、报错处理

报错内容:

Error from server (AlreadyExists): error when creating "kube-flannel.yml": namespaces "kube-flannel" already exists
Error from server (AlreadyExists): error when creating "kube-flannel.yml": clusterroles.rbac.authorization.k8s.io "flannel" already exists
Error from server (AlreadyExists): error when creating "kube-flannel.yml": clusterrolebindings.rbac.authorization.k8s.io "flannel" already exists
Error from server (AlreadyExists): error when creating "kube-flannel.yml": serviceaccounts "flannel" already exists
Error from server (AlreadyExists): error when creating "kube-flannel.yml": configmaps "kube-flannel-cfg" already exists
error parsing kube-flannel.yml: error converting YAML to JSON: yaml: line 71: found a tab character that violates indentation

##kube-flannel已经存在,处理方法:

需要先删除

kubectl delete -f kube-flannel.yml

在创建

kubectl create -f kube-flannel.yml

如果以上错误还是未能解决,需要删除解压下来的文件,重新解压,重新配置即可!

3.4、查看当前master容器中是否已经运行了flannel

docker ps | grep flannel
[root@master01 Documentation]# docker ps | grep flannel
76418b295e4c        registry.aliyuncs.com/google_containers/pause:3.2   "/pause"                 11 minutes ago      Up 11 minutes                           k8s_POD_kube-flannel-ds-2wjmr_kube-flannel_f5f78677-52aa-457a-89cc-ef1320dc3e97_0

3.5、运行kubectl get nodes -owide

kubectl get nodes -owide
[root@master01 Documentation]# kubectl get nodes -owide
NAME       STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master01   Ready    master   23h   v1.19.3   192.168.150.115   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node01     Ready    <none>   21h   v1.19.3   192.168.150.113   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node02     Ready    <none>   21h   v1.19.3   192.168.150.114   <none>        CentOS Linux 7 (Core)   3.10.0-1160.83.1.el7.x86_64   docker://19.3.15

三个节点集群通信完成,可以POD部署!!!

五、部署pod

5、创建空间,创建pod,部署pod

##创建空间

kubectl create –f xxx.yaml

##创建pod

kubectl    run  list-nginx002 --image=nginx:1.14.1

##查看创建pod 详情

kubectl get pods -owide
[root@master01 flannel-master]# kubectl run list-nginx002 --image=nginx:11.14.0
pod/list-nginx002 created
[root@master01 flannel-master]# kubectl get pods
[root@master01 flannel-master]# kubectl get pods -owide
NAME      READY   STATUS              RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
list-nginx002   1/1     ContainerCreating   0          39s   <none>   node02   <none>           <none>

创建完成后可以看到创建pod后状态(kubectl get pods -owide)是否出现了READY 0/1 STATUS ContainerCreating 没有启动起来

六、将删除原来的node重新添加到master控制器集群

1、查看需要加入master集群的命令

kubeadm token create --print-join-command

[root@master01 Documentation]# kubeadm token create --print-join-command
W0505 16:32:38.868062   12052 common.go:148] WARNING: could not obtain a bind address for the API Server: no default routes found in "/proc/net/route" or "/proc/net/ipv6_route"; using: 0.0.0.0
W0505 16:32:39.215877   12052 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
kubeadm join 192.168.150.115:6443 --token 46zqy7.kym6l19og9bcotz8     --discovery-token-ca-cert-hash sha256:b4c66aeb4ff0c65f5180fca24a144e18392921f68cf5b10c18be3e02733e7fdf 
[root@master01 Documentation]# 
[root@master01 Documentation]# 

 2、使用kubeadm reset  将需要添加的node 重置。

kubeadm reset

[root@node02 ~]# kubeadm reset
[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0505 16:39:42.283093   22034 removeetcdmember.go:79] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] No etcd config found. Assuming external etcd
[reset] Please, manually reset etcd to prevent further issues
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[reset] Deleting contents of stateful directories: [/var/lib/kubelet /var/lib/dockershim /var/run/kubernetes /var/lib/cni]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.


3、重新添加node节点到master

需要将在master上查询到的命令在新的node节点上执行

命令:kubeadm join 192.168.150.115:6443 --token 46zqy7.kym6l19og9bcotz8     --discovery-token-ca-cert-hash sha256:b4c66aeb4ff0c65f5180fca24a144e18392921f68cf5b10c18be3e02733e7fdf 

[root@node02 ~]# kubeadm join 192.168.150.115:6443 --token 46zqy7.kym6l19og9bcotz8     --discovery-token-ca-cert-hash sha256:b4c66aeb4ff0c65f5180fca24a144e18392921f68cf5b10c18be3e02733e7fdf
[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 -oyaml'
[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.
4、在master上查询是否添加成功

 kubectl  get node -owide

[root@master01 Documentation]# kubectl  get node -owide
NAME       STATUS   ROLES    AGE    VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master01   Ready    master   7d6h   v1.19.3   192.168.150.115   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node01     Ready    <none>   7d5h   v1.19.3   192.168.150.113   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64         docker://19.3.15
node02     Ready    <none>   11m    v1.19.3   192.168.150.114   <none>        CentOS Linux 7 (Core)   3.10.0-1160.83.1.el7.x86_64   docker://19.3.15
 

七、常见问题及处理

1、问题一:创建pod 出现了状态为0

##查看pod创建后的详情

kubectl  describe pod  linux-nginx1140 

得知:在初始化主节点(master)没有给集群的pod指定内网网段的缘故。(在目录:二、初始化k8s-master 主节点(只在主节点执行) )

错误信息:failed: open /run/flannel/subnet.env: no such file or directory

Successfully assigned default/linux-nginx1140 to node02Warning  FailedCreatePodSandBox  7m18s                    kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "24b119c612b20314ba1c5dcdd292c1239be21c2d94619b7af7118e6b57817e40" network for pod "linux-nginx1140": networkPlugin cni failed to set up pod "linux-nginx1140_default" network: loadFlannelSubnetEnv failed: open /run/flannel/subnet.env: no such file or directory

1.1 解决方法:

可以查看gitgode得到答案Documentation/configuration.md · master · mirrors / flannel-io / flannel · GitCode

If everything works as expected, flanneld should generate a /run/flannel/subnet.env file with IPV6 subnet and network. For example(如果一切正常,flanneld应该生成一个/run/flannel/子网。带IPV6子网和网络的env文件。例如):

FLANNEL_NETWORK=10.42.0.0/16
FLANNEL_SUBNET=10.42.0.1/24
FLANNEL_IPV6_NETWORK=2001:cafe:42::/56
FLANNEL_IPV6_SUBNET=2001:cafe:42::1/64
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true

1.1、处理方法一

1.1.1、在master和node上都创建subnet.env这个文件

查看是否有 /run/flannel/subnet.env 这个文件,master 上是存在的,也有内容:

FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true

各个 node节点上没有此文件,创建目录,新建文件,拷贝文件内容,然后重新创建 pod,正常了。

1.2、处理方法二

重新部署k8s-master 和k8s-node节点

kubeadm reset

重新执行目录二,执行完成后在去部署pod ;

1.3、处理方法三

如果启动pod还是出现错误请查看是否开启scheduler, control-manager的10251,10252端口;

这两个pod的非安全端口没有开启,健康检查时报错,但是由于本身服务是正常的,只是健康检查的端口没启,所以不影响正常使用。

可以通过命令:

kubectl get cs -owide
[root@master01 ~]# kubectl get cs -owide
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS      MESSAGE                                                                                       ERROR
scheduler            Unhealthy   Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused   
controller-manager   Unhealthy   Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused 

1.4、处理方法四

如果启动pod还是出现错误请修改以下配置文件:静态pod的路径:/etc/kubernetes/manifests

  1. vi kube-scheduler.yaml,把port=0那行注释

  2. vi kube-controller-manager.yaml,把port=0那行注释

1.4.1、查看开启scheduler, control-manager的10251,10252端口是否正常

netstat -tulpn 
[root@master01 manifests]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      2952/kubelet        
tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      13288/kube-proxy    
tcp        0      0 192.168.150.115:2379    0.0.0.0:*               LISTEN      8704/etcd           
tcp        0      0 127.0.0.1:2379          0.0.0.0:*               LISTEN      8704/etcd           
tcp        0      0 192.168.150.115:2380    0.0.0.0:*               LISTEN      8704/etcd           
tcp        0      0 127.0.0.1:2381          0.0.0.0:*               LISTEN      8704/etcd           
tcp        0      0 127.0.0.1:10257         0.0.0.0:*               LISTEN      13484/kube-controll 
tcp        0      0 127.0.0.1:10259         0.0.0.0:*               LISTEN      7716/kube-scheduler 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2947/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      3208/master         
tcp        0      0 127.0.0.1:33542         0.0.0.0:*               LISTEN      2952/kubelet        
tcp6       0      0 :::10250                :::*                    LISTEN      2952/kubelet        
tcp6       0      0 :::10251                :::*                    LISTEN      7716/kube-scheduler 
tcp6       0      0 :::6443                 :::*                    LISTEN      8729/kube-apiserver 
tcp6       0      0 :::10252                :::*                    LISTEN      13484/kube-controll 
tcp6       0      0 :::10256                :::*                    LISTEN      13288/kube-proxy    
tcp6       0      0 :::22                   :::*                    LISTEN      2947/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      3208/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           2700/chronyd        
udp6       0      0 ::1:323                 :::*                                2700/chronyd

重新检查

[root@master01 manifests]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE             ERROR
controller-manager   Healthy   ok                  
scheduler            Healthy   ok                  
etcd-0               Healthy   {"health":"true"}

相关文章:

K8S部署及常见问题处理

目录 k8s kubeadm 一键自动化&#xff0c;安装k8s集群&#xff0c;安装所有运行需要的组件 一、环境初始化&#xff08;三台机器都需要执行&#xff09; 主机名、节点ip、部署组件 1、配置hosts&#xff08;主节点master和业务节点node都需要配置&#xff09;文件内容 2、…...

通过Robotstudio修改机器人程序的具体方法和步骤

通过Robotstudio修改机器人程序的具体方法和步骤 基本步骤可参考以下内容: 用网线连接机器人和电脑,机器人一侧要插入LAN2口;机器人和电脑的IP地址要在同一个网段内;请求写入权限;修改程序—编译—应用;加载修改后的程序到机器人;保存Robotstudio程序到电脑端;只能修改…...

第40讲:Python for-in循环语句使用索引遍历序列

文章目录 方法一&#xff1a;遍历的是序列的元素方法二&#xff1a;遍历的是序列的索引方法三&#xff1a;while循环遍历实现方法四&#xff1a;调用内置函数enumerate实现1.什么是enumerate函数2.调用内置函数enumerate实现索引遍历序列 如果在遍历序列的过程中&#xff0c;需…...

如何用Jmeter压测Netty的Echo服务之自定义Jmeter的Java Sampler

前言 如果想要压测一些三方组件&#xff0c;比如MQ&#xff0c;redis什么的&#xff0c;jmeter本身是不支持的。 本文以开发一个压测netty的echo示例&#xff0c;说明如何自定义jmeter的sampler。 开发 本文以idea示例&#xff0c; 新建工程 打开idea新建一个空的maven工程…...

GPT3.5之运用之检查模型是否满足条件

策略三&#xff1a;要求模型检查是否满足条件* 如果任务做出的假设不一定满足&#xff0c;我们可以告诉模型先检查这些假设&#xff0c;如果不满足&#xff0c;指示并停止执行。你还可以考虑潜在的边缘情况以及模型应该如何处理它们&#xff0c;以避免意外的错误或结果。 在如…...

【TCP为什么需要粘包和拆包】

如今&#xff0c;大半个互联网都建立在 TCP 协议之上&#xff0c;我们使用的 HTTP 协议、消息队列、存储、缓存&#xff0c;都需要用到 TCP 协议——这是因为 TCP 协议提供了可靠性。简单来说&#xff0c;可靠性就是让数据无损送达。但若是考虑到成本&#xff0c;就会变得非常复…...

Python | 人脸识别系统 — 姿态检测

本博客为人脸识别系统的姿态检测代码解释 人脸识别系统博客汇总&#xff1a;人脸识别系统-博客索引 项目GitHub地址&#xff1a;Su-Face-Recognition: A face recognition for user logining 注意&#xff1a;阅读本博客前请先参考以下博客 工具安装、环境配置&#xff1a;人脸…...

为什么说网络安全行业是IT行业最后的红利?

前言 2023年网络安全行业的前景看起来非常乐观。根据当前的趋势和发展&#xff0c;一些趋势和发展可能对2023年网络安全行业产生影响&#xff1a; 5G技术的广泛应用&#xff1a;5G技术的普及将会使互联网的速度更快&#xff0c;同时也将带来更多的网络威胁和安全挑战。网络安全…...

谷粒商城二十四Sentinel限流熔断降级

我们在秒杀服务加的以上所有手段都是为了快&#xff0c;除了快之外&#xff0c;我们还需要保证稳定。 我们即使再快也会有一个极限值&#xff0c;现在假设单机下每秒处理一万个单&#xff0c;这已经是超高的处理能力了&#xff0c;秒杀服务上了五台服务器&#xff0c;有三台掉…...

STM32-HAL-SPI-W25Q128FV简单读写测试(2)

文章目录 一、Flash的基本读写操作1.1 向芯片中的某个地址&#xff08;addr:0x02&#xff09;连续写入不定长的数据并读取代码示例读写流程分析函数分析 1.2 向芯片中的某个地址&#xff08;addr:0x00&#xff09;写入一个数值代码示例&#xff1a;读写流程分析 具体的配置接上…...

网易一面:如何设计线程池?请手写一个简单线程池?

说在前面 在40岁老架构师 尼恩的读者社区(50)中&#xff0c;最近有小伙伴拿到了一线互联网企业如极兔、有赞、希音、百度、网易的面试资格&#xff0c;遇到了几个很重要的面试题&#xff1a; 如何设计线程池&#xff1f; 与之类似的、其他小伙伴遇到过的问题还有&#xff1a; …...

网络安全之密码学

目录 密码学 定义 密码的分类 对称加密 非对称加密 对称算法与非对称算法的优缺点 最佳解决办法 --- 用非对称加密算法加密对称加密算法的密钥 非对称加密如何解决对称加密的困境 密钥传输风险 密码管理难 常见算法 对称算法 非对称算法 完整性与身份认证最佳解决…...

第14章 项目采购管理

文章目录 采购管理包括如下几个过程14.2 编制采购计划 462编制采购计划的输出1&#xff09;采购管理计划2&#xff09;采购工作说明书3&#xff09;采购文件 14.2.3 工作说明书&#xff08;SOW&#xff09; 14.3 实施采购 47414.3.2 实施采购的方法和技术 476&#xff08;1&…...

Vite+Vue下的多页面入口配置

我发现多页面入口配置在网上的资料比较乱&#xff0c;今天正好结合我们的开源API分析工具项目&#xff08;APIcat&#xff09;更新情况总结一下。 更新vite.config.js 主要配置的更新是在vite.config.js里面要增加build里的rollupOptions&#xff0c;因为vite底层使用了rollu…...

ChatGPT背后的打工人:你不干,有的是AI干

AI“出圈” 如今&#xff0c;数字技术发展速度惊人&#xff0c;AI提高了社会生产效率&#xff0c;更真切地冲击到原有的生产秩序。 年初AI技术的爆发&#xff0c;让国内看到了进一步降本增效的希望。 国内多家互联网企业相继推出类ChatGPT产品&#xff0c;复旦大学邱锡鹏教授…...

【Access】Access:SQL 语句汇总

目录 一、SQL 的功能 二、考试重点 三、关系的定义 &#xff08;1&#xff09;新建关系 &#xff08;2&#xff09;删除关系 四、SQL 的「数据查询」功能 &#xff08;1&#xff09;基本结构 ① Select 语句的基本结构 ② Select 子句 ③ Where 子句 ④ 空值的处…...

【小样本分割 2022 ECCV】SSP

文章目录 【小样本分割 2022 ECCV】SSP摘要1. 介绍2. 相关工作3. 自支持小样本语义分割3.1 动机3.2 自支持原型-SSM3.3 自适应自支持背景原型-ASBP3.4 自支持匹配-SSL 3. 代码 【小样本分割 2022 ECCV】SSP 论文题目&#xff1a;Self-Support Few-Shot Semantic Segmentation 中…...

Friendlycore增加inodes数量

背景&#xff1a;为Nanopim1安装了core系统&#xff0c;tf卡大小64G&#xff0c;安装后正常扩展到了整个tf卡&#xff0c;但是在安装hass的docker显示磁盘空间不够&#xff0c;最终发现是inode被用完了。其inode只有960K&#xff0c;但是16G卡树莓派系统的inodes都是其两倍。 一…...

Latex 定理和证明类环境(amsthm)和(ntheorm)的区别

最近在写毕业论文&#xff0c;出现了一些定理和证明的环境的问题&#xff0c;问题出现在对两个包的理解程度不够的问题上&#xff1a; \RequirePackage{ntheorem} 1、\newtheorem*{proof}{\hspace{2em}证:} 这个是让证明失去计数原则&#xff0c;该命令不能用于 amsthm 2…...

Yolov8改进---注意力全家桶,小目标涨点

💡💡💡💡💡💡💡💡💡💡注意力全家桶💡💡💡💡💡💡💡💡💡💡💡 基于Yolov8的注意力机制研究,提升小目标、遮挡物、难样本等检测性能...

超短脉冲激光自聚焦效应

前言与目录 强激光引起自聚焦效应机理 超短脉冲激光在脆性材料内部加工时引起的自聚焦效应&#xff0c;这是一种非线性光学现象&#xff0c;主要涉及光学克尔效应和材料的非线性光学特性。 自聚焦效应可以产生局部的强光场&#xff0c;对材料产生非线性响应&#xff0c;可能…...

电脑插入多块移动硬盘后经常出现卡顿和蓝屏

当电脑在插入多块移动硬盘后频繁出现卡顿和蓝屏问题时&#xff0c;可能涉及硬件资源冲突、驱动兼容性、供电不足或系统设置等多方面原因。以下是逐步排查和解决方案&#xff1a; 1. 检查电源供电问题 问题原因&#xff1a;多块移动硬盘同时运行可能导致USB接口供电不足&#x…...

Axios请求超时重发机制

Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式&#xff1a; 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...

LabVIEW双光子成像系统技术

双光子成像技术的核心特性 双光子成像通过双低能量光子协同激发机制&#xff0c;展现出显著的技术优势&#xff1a; 深层组织穿透能力&#xff1a;适用于活体组织深度成像 高分辨率观测性能&#xff1a;满足微观结构的精细研究需求 低光毒性特点&#xff1a;减少对样本的损伤…...

STM32---外部32.768K晶振(LSE)无法起振问题

晶振是否起振主要就检查两个1、晶振与MCU是否兼容&#xff1b;2、晶振的负载电容是否匹配 目录 一、判断晶振与MCU是否兼容 二、判断负载电容是否匹配 1. 晶振负载电容&#xff08;CL&#xff09;与匹配电容&#xff08;CL1、CL2&#xff09;的关系 2. 如何选择 CL1 和 CL…...

关于easyexcel动态下拉选问题处理

前些日子突然碰到一个问题&#xff0c;说是客户的导入文件模版想支持部分导入内容的下拉选&#xff0c;于是我就找了easyexcel官网寻找解决方案&#xff0c;并没有找到合适的方案&#xff0c;没办法只能自己动手并分享出来&#xff0c;针对Java生成Excel下拉菜单时因选项过多导…...

华为OD机试-最短木板长度-二分法(A卷,100分)

此题是一个最大化最小值的典型例题&#xff0c; 因为搜索范围是有界的&#xff0c;上界最大木板长度补充的全部木料长度&#xff0c;下界最小木板长度&#xff1b; 即left0,right10^6; 我们可以设置一个候选值x(mid)&#xff0c;将木板的长度全部都补充到x&#xff0c;如果成功…...

QT开发技术【ffmpeg + QAudioOutput】音乐播放器

一、 介绍 使用ffmpeg 4.2.2 在数字化浪潮席卷全球的当下&#xff0c;音视频内容犹如璀璨繁星&#xff0c;点亮了人们的生活与工作。从短视频平台上令人捧腹的搞笑视频&#xff0c;到在线课堂中知识渊博的专家授课&#xff0c;再到影视平台上扣人心弦的高清大片&#xff0c;音…...

react-pdf(pdfjs-dist)如何兼容老浏览器(chrome 49)

之前都是使用react-pdf来渲染pdf文件&#xff0c;这次有个需求是要兼容xp环境&#xff0c;xp上chrome最高支持到49&#xff0c;虽然说iframe或者embed都可以实现预览pdf&#xff0c;但为了后续的定制化需求&#xff0c;还是需要使用js库来渲染。 chrome 49测试环境 能用的测试…...

Docker环境下安装 Elasticsearch + IK 分词器 + Pinyin插件 + Kibana(适配7.10.1)

做RAG自己打算使用esmilvus自己开发一个&#xff0c;安装时好像网上没有比较新的安装方法&#xff0c;然后找了个旧的方法对应试试&#xff1a; &#x1f680; 本文将手把手教你在 Docker 环境中部署 Elasticsearch 7.10.1 IK分词器 拼音插件 Kibana&#xff0c;适配中文搜索…...