Kubernetes服务搭建[配置-部署](Kubeadm)

news2024/11/21 1:42:54

文章目录

  • **[1 — 7] ** [ 配置K8S主从集群前置准备操作 ]
  • 一:主节点操作 查看主机域名->编辑域名
    • 1.1 编辑HOST 从节点也做相应操作
    • 1.2 从节点操作 查看从节点102域名->编辑域名
    • 1.3 从节点操作 查看从节点103域名->编辑域名
  • 二:安装自动填充,虚拟机默认没有
  • 三:关闭防火墙
  • 四:关闭交换空间
  • 五:禁用 Selinux
  • 六: 允许 ip tables 检查桥接流量
  • 七:设置K8S相关系统参数
    • 7.0:镜像加速
    • 7.1:K8S仓库
    • 7.2:配置 sysctl 参数,重新启动后配置不变
      • 7.3.2:配置sysctl 内核参数而不重新启动
  • 八:安装K8S -- kubelet,kubeadm,kubectl核心组件
    • 8.1:安装命令
  • pre-9 注意:安装网络插件coredns,否则在第九步执行init会卡住
    • pre-9.1: 安装coredns
    • pre-9.2: 注意:查看coredns pod状态Ready=0
      • pre-9.2.1: 执行 kubectl get pods -n kube-system查看日志输出
      • pre-9.2.2: 查看pod错误日志输出 kubectl describe pod coredns-545d6fc579-fknqn -n kube-system
      • pre-9.2.3: 安装Colico网络通信插件
        • 9.2.3.1 - 执行: wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
        • 9.2.3.2 - 修改calico.yaml
        • 9.2.3.3 - 执行 kubectl apply -f calico.yaml
          • 注意异常:error converting YAML
          • 执行成功
          • 查看coredns pod节点状态
  • 九:kubeadm init生成Node
    • 9.1: 注意主从节点分别执行,address不一样
      • 9.1.1:master节点操作address=192.168.56.101
      • 9.1.2:node节点操作address=192.168.56.102
    • 9.2: 上述会生成如下日志说明成功
      • 9.2.1: 注意主从从节点分别在尾部生成token
    • 9.3: 注意:在从节点执行主节点init对应生成的join命令
  • 十:配置K8S主从节点的网络通信
    • 10.1 查看node和pod 对应status 状态 发现master和node状态为 [NotReady]
    • 10.2 查看K8S异常信息命令 journalctl -f -u kubelet
    • 10.3 配置calico网络
    • 10.4 修改calico.yaml
    • 10.5 K8S部署calico容器
    • 10.6 再次查看节点状态 kubectl get nodes -o wide [ status状态为Ready ]

**[1 — 7] ** [ 配置K8S主从集群前置准备操作 ]

一:主节点操作 查看主机域名->编辑域名

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# hostname
master
[root@localhost ~]#

1.1 编辑HOST 从节点也做相应操作

[root@vbox-master-01-vbox-01 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.101  master
192.168.56.102  node

1.2 从节点操作 查看从节点102域名->编辑域名

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname node
[root@localhost ~]# hostname
node

1.3 从节点操作 查看从节点103域名->编辑域名

[root@localhost /]# hostname
localhost.localdomain
[root@localhost /]# hostnamectl set-hostname nodeslavethree
[root@localhost /]# hostname
nodeslavethree

二:安装自动填充,虚拟机默认没有

[root@vbox-master-01-vbox-01 ~]# yum -y install bash-completion
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Determining fastest mirrors
 * base: ftp.sjtu.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.aliyun.com

三:关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

四:关闭交换空间

free -h
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
free -h

五:禁用 Selinux

sed -i “s/^SELINUX=enforcing/SELINUX=disabled/g” /etc/sysconfig/selinux

[root@nodemaster /]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
cat /etc/selinux/config

六: 允许 ip tables 检查桥接流量

iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT

七:设置K8S相关系统参数

7.0:镜像加速

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

7.1:K8S仓库

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
# 是否检查 gpg 签名文件
gpgcheck=0
# 是否检查 gpg 签名文件
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF

7.2:配置 sysctl 参数,重新启动后配置不变

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

7.3.2:配置sysctl 内核参数而不重新启动

sysctl --system

八:安装K8S – kubelet,kubeadm,kubectl核心组件

8.1:安装命令

[root@master local]# sudo yum install -y kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0 --disableexcludes=kubernetes --nogpgcheck
[root@node local]# sudo yum install -y kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0 --disableexcludes=kubernetes --nogpgcheck
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
kubernetes                                                                                              | 1.4 kB  00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 kubeadm.x86_64.0.1.21.0-0 将被 安装
--> 正在处理依赖关系 kubernetes-cni >= 0.8.6,它被软件包 kubeadm-1.21.0-0.x86_64 需要
---> 软件包 kubectl.x86_64.0.1.21.0-0 将被 安装
---> 软件包 kubelet.x86_64.0.1.21.0-0 将被 安装
--> 正在检查事务
---> 软件包 kubernetes-cni.x86_64.0.1.2.0-0 将被 安装
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================
 Package                           架构                      版本                          源                             大小
===============================================================================================================================
正在安装:
 kubeadm                           x86_64                    1.21.0-0                      kubernetes                    9.1 M
 kubectl                           x86_64                    1.21.0-0                      kubernetes                    9.5 M
 kubelet                           x86_64                    1.21.0-0                      kubernetes                     20 M
为依赖而安装:
 kubernetes-cni                    x86_64                    1.2.0-0                       kubernetes                     17 M

事务概要
===============================================================================================================================
安装  3 软件包 (+1 依赖软件包)

总下载量:55 M
安装大小:248 M
Downloading packages:
(1/4): dc4816b13248589b85ee9f950593256d08a3e6d4e419239faf7a83fe686f641c-kubeadm-1.21.0-0.x86_64.rpm     | 9.1 MB  00:00:44
(2/4): d625f039f4a82eca35f6a86169446afb886ed9e0dfb167b38b706b411c131084-kubectl-1.21.0-0.x86_64.rpm     | 9.5 MB  00:00:46
(3/4): 0f2a2afd740d476ad77c508847bad1f559afc2425816c1f2ce4432a62dfe0b9d-kubernetes-cni-1.2.0-0.x86_64.r |  17 MB  00:01:21
(4/4): 13b4e820d82ad7143d786b9927adc414d3e270d3d26d844e93eff639f7142e50-kubelet-1.21.0-0.x86_64.rpm     |  20 MB  00:01:39
-------------------------------------------------------------------------------------------------------------------------------
总计                                                                                           395 kB/s |  55 MB  00:02:23
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : kubernetes-cni-1.2.0-0.x86_64                                                                              1/4
  正在安装    : kubelet-1.21.0-0.x86_64                                                                                    2/4
  正在安装    : kubectl-1.21.0-0.x86_64                                                                                    3/4
  正在安装    : kubeadm-1.21.0-0.x86_64                                                                                    4/4
  验证中      : kubelet-1.21.0-0.x86_64                                                                                    1/4
  验证中      : kubeadm-1.21.0-0.x86_64                                                                                    2/4
  验证中      : kubectl-1.21.0-0.x86_64                                                                                    3/4
  验证中      : kubernetes-cni-1.2.0-0.x86_64                                                                              4/4

已安装:
  kubeadm.x86_64 0:1.21.0-0                 kubectl.x86_64 0:1.21.0-0                 kubelet.x86_64 0:1.21.0-0

作为依赖被安装:
  kubernetes-cni.x86_64 0:1.2.0-0

完毕!

pre-9 注意:安装网络插件coredns,否则在第九步执行init会卡住

pre-9.1: 安装coredns

docker pull coredns/coredns
docker tag coredns/coredns:latest
docker tag coredns/coredns:latest registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0
[root@master kubernetes]# docker pull coredns/coredns
Using default tag: latest
latest: Pulling from coredns/coredns
d92bdee79785: Pull complete
6e1b7c06e42d: Pull complete
Digest: sha256:5b6ec0d6de9baaf3e92d0f66cd96a25b9edbce8716f5f15dcd1a616b3abd590e
Status: Downloaded newer image for coredns/coredns:latest
docker.io/coredns/coredns:latest
[root@master kubernetes]# docker tag coredns/coredns:latest
"docker tag" requires exactly 2 arguments.
See 'docker tag --help'.

Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

[root@master kubernetes]# docker tag coredns/coredns:latest registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0

pre-9.2: 注意:查看coredns pod状态Ready=0

pre-9.2.1: 执行 kubectl get pods -n kube-system查看日志输出

[root@master soft]# kubectl get pods -n kube-system
NAME                             READY   STATUS              RESTARTS   AGE
coredns-545d6fc579-fknqn         0/1     ContainerCreating   0          6m41s
coredns-545d6fc579-s22rb         0/1     ContainerCreating   0          6m41s
etcd-master                      1/1     Running             0          6m49s
kube-apiserver-master            1/1     Running             0          6m49s
kube-controller-manager-master   1/1     Running             0          6m49s
kube-proxy-56ppg                 1/1     Running             0          6m41s
kube-proxy-pp7d6                 1/1     Running             0          85s
kube-scheduler-master            1/1     Running             0          6m48s

pre-9.2.2: 查看pod错误日志输出 kubectl describe pod coredns-545d6fc579-fknqn -n kube-system

主要是:check that the calico/node container is running and has mounted /var/lib/calico/
说明colico网络插件没有配置,容器没有运行
[root@master soft]# kubectl describe pod coredns-545d6fc579-fknqn -n kube-system
Name:                 coredns-545d6fc579-fknqn
Namespace:            kube-system
Priority:             2000000000
Priority Class Name:  system-cluster-critical
Node:                 master/192.168.56.101
Start Time:           Thu, 04 May 2023 18:02:01 +0800
Labels:               k8s-app=kube-dns
                      pod-template-hash=545d6fc579
Annotations:          <none>
Status:               Pending
IP:
IPs:                  <none>
Controlled By:        ReplicaSet/coredns-545d6fc579
Containers:
  coredns:
    Container ID:
    Image:         registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0
    Image ID:
    Ports:         53/UDP, 53/TCP, 9153/TCP
    Host Ports:    0/UDP, 0/TCP, 0/TCP
    Args:
      -conf
      /etc/coredns/Corefile
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Limits:
      memory:  170Mi
    Requests:
      cpu:        100m
      memory:     70Mi
    Liveness:     http-get http://:8080/health delay=60s timeout=5s period=10s #success=1 #failure=5
    Readiness:    http-get http://:8181/ready delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment:  <none>
    Mounts:
      /etc/coredns from config-volume (ro)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-mzbf7 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  config-volume:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      coredns
    Optional:  false
  kube-api-access-mzbf7:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              kubernetes.io/os=linux
Tolerations:                 CriticalAddonsOnly op=Exists
                             node-role.kubernetes.io/control-plane:NoSchedule
                             node-role.kubernetes.io/master:NoSchedule
                             node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason                  Age                   From               Message
  ----     ------                  ----                  ----               -------
  Warning  FailedScheduling        13m                   default-scheduler  0/1 nodes are available: 1 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn't tolerate.
  Normal   Scheduled               13m                   default-scheduler  Successfully assigned kube-system/coredns-545d6fc579-fknqn to master
  Warning  FailedScheduling        13m                   default-scheduler  0/1 nodes are available: 1 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn't tolerate.
  Warning  FailedCreatePodSandBox  13m                   kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "4150bf828bb587a7f27efcd33b96e534f26951949779c572bedd09f57d6211ff" network for pod "coredns-545d6fc579-fknqn": networkPlugin cni failed to set up pod "coredns-545d6fc579-fknqn_kube-system" network: stat /var/lib/calico/nodename: no such file or directory: check that the calico/node container is running and has mounted /var/lib/calico/
  Warning  FailedCreatePodSandBox  13m                   kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "98ea203f10a10ac5398693a9702a130224ec23f30335e6d33212eb6af3289c4a" network for pod "coredns-545d6fc579-fknqn": networkPlugin cni failed to set up pod "coredns-545d6fc579-fknqn_kube-system" network: stat /var/lib/calico/nodename: no such file or directory: check that the calico/node container is running and has mounted /var/lib/calico/

pre-9.2.3: 安装Colico网络通信插件

9.2.3.1 - 执行: wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml

[root@master kubernetes]# wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
--2023-05-03 02:23:02--  https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
正在解析主机 projectcalico.docs.tigera.io (projectcalico.docs.tigera.io)... 13.228.199.255, 18.139.194.139, 2406:da18:880:3800::c8, ...
正在连接 projectcalico.docs.tigera.io (projectcalico.docs.tigera.io)|13.228.199.255|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:238089 (233K) [text/yaml]
正在保存至: “calico.yaml”

100%[=====================================================================================>] 238,089      392KB/s 用时 0.6s

2023-05-03 02:23:03 (392 KB/s) - 已保存 “calico.yaml” [238089/238089])

9.2.3.2 - 修改calico.yaml

[root@master kubernetes]# vi calico.yaml
# CLUSTER_TYPE 下方添加信息
- name: CLUSTER_TYPE
  value: "k8s,bgp"
  # 下方为新增内容
- name: IP_AUTODETECTION_METHOD
  value: "interface=网卡名称[如 ens33]

9.2.3.3 - 执行 kubectl apply -f calico.yaml

注意异常:error converting YAML

查看yaml文件内容发现刚刚改的缩进不对

执行成功
[root@master soft]# kubectl apply -f calico.yaml
poddisruptionbudget.policy/calico-kube-controllers configured
serviceaccount/calico-kube-controllers unchanged
serviceaccount/calico-node unchanged
configmap/calico-config unchanged
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/ipreservations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org configured
clusterrole.rbac.authorization.k8s.io/calico-kube-controllers unchanged
clusterrole.rbac.authorization.k8s.io/calico-node unchanged
clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers unchanged
clusterrolebinding.rbac.authorization.k8s.io/calico-node unchanged
daemonset.apps/calico-node created
deployment.apps/calico-kube-controllers created
查看coredns pod节点状态

九:kubeadm init生成Node

9.1: 注意主从节点分别执行,address不一样

9.1.1:master节点操作address=192.168.56.101

kubeadm init --kubernetes-version=v1.21.0 --image-repository=registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.56.101

9.1.2:node节点操作address=192.168.56.102

kubeadm init --kubernetes-version=v1.21.0 --image-repository=registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.56.102

9.2: 上述会生成如下日志说明成功

9.2.1: 注意主从从节点分别在尾部生成token

主节点生成:

kubeadm join 192.168.56.101:6443 --token ofgeif.siy6c7i3bkwd8zhe \
         --discovery-token-ca-cert-hash sha256:153569126910a8000fc13dab0ef9123f3c798d392965b3555415951d20d7fcf9

从节点生成:

kubeadm join 192.168.56.102:6443 --token hyixs7.p3qz6w2lglxv5p5o \
        --discovery-token-ca-cert-hash sha256:1ffcb2d4d8acd6da8c5dc1abbb8b3035d5fb53705660b9275fe8972e6e08cbd0
        
[root@node local]# kubeadm init --image-repository=registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.16                         8.56.102
I0503 02:13:29.368712   19886 version.go:254] remote version is much newer: v1.27.1; falling back to: stable-1.21
[init] Using Kubernetes version: v1.21.14
[preflight] Running pre-flight checks
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 23.0.5. Latest validated ve                         rsion: 20.10
[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 node] and IPs [10.96.0.1 192.168.56.102]
[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 node] and IPs [192.168.56.102 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost node] and IPs [192.168.56.102 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] WARNING: unable to stop the kubelet service momentarily: [exit status 5]
[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/manife                         sts". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
[apiclient] All control plane components are healthy after 60.507892 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.21" in namespace kube-system with the configuration for the kubelets in the cl                         uster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node node as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) n                         ode-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node node as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: hyixs7.p3qz6w2lglxv5p5o
[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 certifi                         cate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap To                         ken
[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.56.102:6443 --token hyixs7.p3qz6w2lglxv5p5o \
        --discovery-token-ca-cert-hash sha256:1ffcb2d4d8acd6da8c5dc1abbb8b3035d5fb53705660b9275fe8972e6e08cbd0

9.3: 注意:在从节点执行主节点init对应生成的join命令

[root@node local]# kubeadm join 192.168.56.101:6443 --token ofgeif.siy6c7i3bkwd8zhe \
         --discovery-token-ca-cert-hash sha256:153569126910a8000fc13dab0ef9123f3c798d392965b3555415951d20d7fcf9
[preflight] Running pre-flight checks
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 23.0.5. Latest validated ve                         rsion: 20.10
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR DirAvailable--etc-kubernetes-manifests]: /etc/kubernetes/manifests is not empty
        [ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
        [ERROR Port-10250]: Port 10250 is in use
        [ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
[root@node local]# kubeadm reset
[reset] Reading configuration from the cluster...
[reset] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[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
[reset] Removing info for node "node" from the ConfigMap "kubeadm-config" in the "kube-system" Namespace
[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/ku                         bernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[reset] Deleting contents of stateful directories: [/var/lib/etcd /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.
[root@node local]# kubeadm join 192.168.56.101:6443 --token ofgeif.siy6c7i3bkwd8zhe         --discovery-token-ca-cert-hash sha2                         56:153569126910a8000fc13dab0ef9123f3c798d392965b3555415951d20d7fcf9
[preflight] Running pre-flight checks
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 23.0.5. Latest validated ve                         rsion: 20.10
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[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.

[root@node local]#  kubectl get nodes
NAME     STATUS     ROLES                  AGE    VERSION
master   NotReady   control-plane,master   39m    v1.21.0
node     NotReady   <none>                 101s   v1.21.0
[root@node local]# kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                             READY   STATUS    RESTARTS      AGE    IP               NODE     NOMINATED NODE                            READINESS GATES
kube-system   coredns-545d6fc579-p4pj4         0/1     Pending   0             39m    <none>           <none>   <none>                                    <none>
kube-system   coredns-545d6fc579-r8cnv         0/1     Pending   0             39m    <none>           <none>   <none>                                    <none>
kube-system   etcd-master                      1/1     Running   0             40m    192.168.56.101   master   <none>                                    <none>
kube-system   kube-apiserver-master            1/1     Running   1 (40m ago)   40m    192.168.56.101   master   <none>                                    <none>
kube-system   kube-controller-manager-master   1/1     Running   0             40m    192.168.56.101   master   <none>                                    <none>
kube-system   kube-proxy-72w98                 1/1     Running   0             2m5s   192.168.56.102   node     <none>                                    <none>
kube-system   kube-proxy-zc2f7                 1/1     Running   0             39m    192.168.56.101   master   <none>                                    <none>
kube-system   kube-scheduler-master            1/1     Running   0             40m    192.168.56.101   master   <none>                                    <none>
[root@node local]# systemctl start kubelet

十:配置K8S主从节点的网络通信

10.1 查看node和pod 对应status 状态 发现master和node状态为 [NotReady]

[root@master kubernetes]# kubectl get nodes -o wide
NAME     STATUS     ROLES                  AGE     VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master   NotReady   control-plane,master   40m     v1.21.0   192.168.56.101   <none>        CentOS Linux 7 (Core)   3.10.0-1160.88.1.el7.x86_64   docker://23.0.5
node     NotReady   <none>                 2m30s   v1.21.0   192.168.56.102   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64        docker://23.0.5

10.2 查看K8S异常信息命令 journalctl -f -u kubelet

[root@master kubernetes]# journalctl -f -u kubelet

[root@master kubernetes]# journalctl -f -u kubelet
-- Logs begin at 三 2023-05-03 01:04:05 CST. --
5月 03 02:30:24 master kubelet[5376]: E0503 02:30:24.876889    5376 kubelet.go:2218] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"
5月 03 02:30:26 master kubelet[5376]: I0503 02:30:26.182120    5376 cni.go:239] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
5月 03 02:30:29 master kubelet[5376]: E0503 02:30:29.896174    5376 kubelet.go:2218] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"

10.3 配置calico网络

wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml

[root@master kubernetes]# wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
--2023-05-03 02:23:02--  https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
正在解析主机 projectcalico.docs.tigera.io (projectcalico.docs.tigera.io)... 13.228.199.255, 18.139.194.139, 2406:da18:880:3800::c8, ...
正在连接 projectcalico.docs.tigera.io (projectcalico.docs.tigera.io)|13.228.199.255|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:238089 (233K) [text/yaml]
正在保存至: “calico.yaml”

100%[=====================================================================================>] 238,089      392KB/s 用时 0.6s

2023-05-03 02:23:03 (392 KB/s) - 已保存 “calico.yaml” [238089/238089])


10.4 修改calico.yaml

[root@master kubernetes]# vi calico.yaml
# CLUSTER_TYPE 下方添加信息
- name: CLUSTER_TYPE
  value: "k8s,bgp"
  # 下方为新增内容
- name: IP_AUTODETECTION_METHOD
  value: "interface=网卡名称

在这里插入图片描述

10.5 K8S部署calico容器

kubectl apply -f calico.yaml

10.6 再次查看节点状态 kubectl get nodes -o wide [ status状态为Ready ]

[root@node local]# kubectl get nodes -o wide
NAME     STATUS   ROLES                  AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                                         CONTAINER-RUNTIME
master   Ready    control-plane,master   58m   v1.21.0   192.168.56.101   <none>        CentOS Linux 7 (Core)   3.10.0-1160.88.                         1.el7.x86_64   docker://23.0.5
node     Ready    <none>                 20m   v1.21.0   192.168.56.102   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7                         .x86_64        docker://23.0.5

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/491605.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Android - 动画

一、概念 补间动画 ViewAnimation&#xff08;Tween&#xff09;&#xff1a;不改变view的位置和属性。属性动画PeopertyAnimation&#xff1a;view的属性根据执行的动画发生真实的改变。帧动画 DrawableAnimation&#xff08;Frame&#xff09;&#xff1a; 二、补间动画 Vi…

SPSS如何进行使用时间序列模型之案例实训?

文章目录 0.引言1.时间序列数据平稳处理2.指数平滑法建模3.ARIMA建模4.季节性分解 0.引言 因科研等多场景需要进行绘图处理&#xff0c;笔者对SPSS进行了学习&#xff0c;本文通过《SPSS统计分析从入门到精通》及其配套素材结合网上相关资料进行学习笔记总结&#xff0c;本文对…

MYSQL用户组管理

1&#xff1a;使用明文密码创建用户 使用密文密码创建用户 1.2 查看用户信息 1.3 重命名用户 rename 1.4 删除用户信息 drop 1.5 修改当前登录用户的密码 set password password(123456); 1.6 修改其他用户的密码 set password for nancylocalhost password(abc123); 1.7…

2023年常见的20道JavaScript面试题及其答案解析,你知道多少

JavaScript中typeof操作符有哪些返回值&#xff1f; 答案&#xff1a;typeof操作符返回字符串数据类型。可能的返回值有&#xff1a;“undefined”、“boolean”、“number”、“string”、“object"和"function”。如何检查一个变量是否为数组&#xff1f; 答案&…

【JavaEE】Thread类

目录 前言 1、创建一个线程 1.1、 体会多线程的执行 1.2、体会单线程的执行 1.3、sleep方法&#xff08;休眠&#xff09; 1.4、通过第三方程序来观察线程详情 1.5、创建线程的方式 1.5.1、继承Thread类&#xff0c;重写run方法来创建线程 1.5.2、实现Runnable接口&am…

linux 查看系统版本

文章目录 一、查看Linux内核版本的命令二、查看Linux系统发行版本的命令三、 延伸&#xff1a; 一、查看Linux内核版本的命令 cat /proc/version 此命令可以查看正在运行的内核版本信息。/proc 目录存储的是当前内核运行状态的一系列特殊文件&#xff0c;包括&#xff1a;内存…

electron源码保护

electron 程序发布后&#xff0c;如果未对程序做保护&#xff0c;则极容易受到破坏&#xff0c;比如被轻松破解密码&#xff0c;或者被修改程序&#xff0c;所以必须对程序做一些安全防护。虽然没有100%的安全防护&#xff0c;但是提升破解难度&#xff0c;直至破解代价超出了范…

UML图中的domain model,object model,system sequence diagram以及interaction diagram

UML图&#xff08;Unified Modeling Language&#xff0c;统一建模语言&#xff09;是一种用于描述、可视化、构建和记录软件系统的标准化建模语言。在UML中&#xff0c;有很多类型的图&#xff0c;其中包括领域模型&#xff08;Domain Model&#xff09;、对象模型&#xff08…

拥抱智能时代:初探RFID系统

在数字化时代&#xff0c;人们越来越追求高效率和高质量的体验&#xff0c;以获得更快乐、更好的生活。RFID系统作为一项智能化管理技术&#xff0c;正越来越广泛地应用于各个领域&#xff0c;以提高效率和质量。本文将介绍RFID系统的基本概念、工作原理和实际应用案例&#xf…

OpenAI的编程语言和框架,给程序员带来了帮助有哪些

OpenAI 是一个人工智能开发公司&#xff0c;成立于2015年&#xff0c;总部位于美国旧金山。这家公司致力于研究和开发先进的人工智能技术&#xff0c;旨在将这些技术应用到解决全球一些最棘手的问题上。 OpenAI 以其卓越的技术和实验室出品的 groundbreaking AI papers 而闻名…

Android焦点流程梳理

作者&#xff1a;Cy13er 前言 最近在看一些焦点处理的问题&#xff0c;认真处理起来发现不跟着源码自己走一遍焦点相关的流程&#xff0c;对于问题的分析上会比较困难。所以本文主要对焦点流程进行一次梳理&#xff0c;在处理类似问题时也可以作为手册阅读。 起源 一切都要从…

Apache Kafka 进阶(一)

官网 Apache Kafka是一个开源的分布式事件流平台&#xff0c;被数千家公司用于高性能数据管道、流分析、数据集成和关键任务应用。 核心能力 高吞吐量 在网络有限的吞吐量下&#xff0c;使用延迟低至2ms的机器集群交付消息。可扩展性 将生产集群扩展到1000个代理&#xff0c…

SQLite安装配置

1.什么是 SQLite&#xff1f; SQLite是一个软件库&#xff0c;实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite是一个增长最快的数据库引擎&#xff0c;这是在普及方面的增长&#xff0c;与它的尺寸大小无关。SQLite源代码不受版权限制。 SQLite是…

Linux 五种网络IO模式(阻塞IO、非阻塞IO、IO多路复用、信号驱动IO、异步IO)

Linux网络编程中&#xff0c;有五种网络IO模式&#xff0c;分别是阻塞IO、非阻塞IO、IO多路复用、信号驱动IO、异步IO&#xff1b; 虽然说不能全都认识得很透彻&#xff0c;但至少得都知道一点&#xff01; 开始之前&#xff0c;先了解以下同步IO和异步IO&#xff1b; 1. 同步…

探索AIGC创新实践,亚马逊云科技与全球咨询合作伙伴携手同行

AIGC(AI Generated Content&#xff0c;人工智能生成内容)&#xff0c;已经成为全球出圈的科技热点。各行各业都在重新审视和思考AIGC的创新价值、未来趋势和成功实践&#xff0c;力争在这波热潮下寻找更多创新的可能性&#xff0c;重塑行业格局。 在AIGC领域&#xff0c;亚马…

无代码资讯|ChatGPT新功能曝光;Mendix与亚马逊云科技底层融合;无代码开发平台Appy Pie推出内置AI

栏目导读&#xff1a;无代码资讯栏目从全球视角出发&#xff0c;带您了解无代码相关最新资讯。 Top3大事件 1、ChatGPT 新功能曝光&#xff0c;GPT-4 迎来 AGI 历史性时刻&#xff01; 北美时间4月20日&#xff0c;Open AI联合创始人Greg Brockman受邀出席 “2023TED” 大会&…

手写【深拷贝】

JS中深拷贝的实现 JSON.parse(JSON.stringify())递归实现深拷贝 使用JSON.parse(JSON.stringify()) 实现 无法拷贝 函数、正则、时间格式、原型上的属性和方法等 递归实现深拷贝 es5实现深拷贝 源对象 const obj {name: 张桑,age: 18,hobby: [{name: 篮球,year: 5,loveSta…

极简爬虫通用模板

网络爬虫的一般步骤如下&#xff1a; 1、确定爬取目标&#xff1a;确定需要爬取的数据类型和来源网站。 2、制定爬取策略&#xff1a;确定爬取哪些网页、如何爬取和频率等。 3、构建爬虫程序&#xff1a;使用编程语言&#xff08;如Python&#xff09;实现爬虫程序&#xff…

【python】列表、字典、元组与集合的特点以及对比

一、列表&#xff08;List&#xff09; 1. 列表的特点 数据按顺序存储列表有正序、倒序两种索引列表可存储任意类型的数据&#xff0c;并且允许重复。 2. 列表的遍历&#xff1a; lst[1,2,3] for i in range(len(lst)):print(lst[i],end" ")3. 列表的缺点&#x…

虹科方案 | HK-TrueNAS:音频协作的理想存储

一、虹科HK-TRUENAS 非常适合 AVID PRO TOOLS™ 专业音频编辑和大多数媒体和娱乐 (M&E) 工作流程从录制开始&#xff0c;经过后期制作&#xff0c;最后进入播放。这一过程可能需要几个月的时间来拍摄一部大型的电影&#xff0c;也可能需要几个小时甚至几分钟的时间来播放最…