Chinaunix首页 | 论坛 | 博客
  • 博客访问: 122727
  • 博文数量: 165
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1655
  • 用 户 组: 普通用户
  • 注册时间: 2022-09-26 14:37
文章分类

全部博文(165)

文章存档

2024年(2)

2023年(95)

2022年(68)

我的朋友

分类: 系统运维

2022-11-03 14:06:24

环境

准备工作

配置ansible(deploy 主机执行)


点击(此处)折叠或打开

  1. # ssh-keygen# for i in 192.168.3.{21..28}; do ssh-copy-id -i ~/.ssh/id_rsa.pub $i; done优化主机配置

点击(此处)折叠或打开

  1. [root@deploy ~]# cat /etc/ansible/hosts
  2. [etcd]
  3. 192.168.3.21
  4. 192.168.3.22
  5. 192.168.3.23
  6. [k8s-master]
  7. 192.168.3.24
  8. 192.168.3.25
  9. 192.168.3.26
  10. [k8s-worker]
  11. 192.168.3.27
  12. 192.168.3.28

  13. [k8s:children]
  14. k8s-master
  15. k8s-worker


关闭防火墙和selinux


点击(此处)折叠或打开

  1. # ansible all -m shell -a "systemctl stop firewalld && systemctl disable firewalld"
  2. # ansible all -m shell -a "sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config"


修改limit

关闭交换分区


点击(此处)折叠或打开

  1. # swapoff -a
  2. # ansible k8s -m shell -a "yes | cp /etc/fstab /etc/fstab_bak"
  3. # ansible k8s -m shell -a "cat /etc/fstab_bak | grep -v swap > /etc/fstab"
  4. # ansible k8s -m shell -a "echo vm.swappiness = 0 >> /etc/sysctl.d/k8s.conf"
  5. # ansible k8s -m shell -a "sysctl -p /etc/sysctl.d/k8s.conf"


配置ipvs


点击(此处)折叠或打开

  1. # cat /root/ipvs.sh
  2. #!/bin/bash
  3. yum -y install ipvsadm ipset
  4. ####创建ipvs脚本
  5.  
  6. cat > /etc/sysconfig/modules/ipvs.modules << EOF
  7. #!/bin/bash
  8. modprobe -- ip_vs
  9. modprobe -- ip_vs_rr
  10. modprobe -- ip_vs_wrr
  11. modprobe -- ip_vs_sh
  12. modprobe -- nf_conntrack_ipv4
  13. EOF
  14.  
  15. ####执行脚本,验证配置
  16.  
  17. chmod 755 /etc/sysconfig/modules/ipvs.modules
  18. bash /etc/sysconfig/modules/ipvs.modules
  19. lsmod | grep -e ip_vs -e nf_conntrack_ipv4

  20. #########################

  21. # ansible k8s -m script -a "/root/ipvs.sh"


配置网桥转发规则


点击(此处)折叠或打开

  1. # cat sysctl.sh
  2. #!/bin/bash
  3. cat > /etc/sysctl.d/k8s.conf << EOF
  4. net.bridge.bridge-nf-call-ip6tables = 1
  5. net.bridge.bridge-nf-call-iptables = 1
  6. net.ipv4.ip_forward = 1
  7. EOF

  8. cat <<EOF | tee /etc/modules-load.d/crio.conf
  9. overlay
  10. br_netfilter
  11. EOF
  12. modprobe overlay
  13. modprobe br_netfilter
  14. sysctl --system

点击(此处)折叠或打开

  1. # ansible k8s -m script -a "/root/sysctl.sh"


配置etcd集群

生成证书(ansible 主机操作)


点击(此处)折叠或打开

  1. # curl -o /usr/bin/cfssl https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
  2. # curl -o /usr/bin/cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
  3. # curl -o /usr/bin/cfssl-certinfo https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
  4. # chmod +x /usr/bin/cfssl*


创建 CA 证书签名请求

点击(此处)折叠或打开

  1. # cat >ca-csr.json <<EOF
  2. {
  3. "CN": "etcd",
  4. "key": {
  5. "algo": "rsa",
  6. "size": 2048
  7. },
  8. "names": [
  9. {
  10. "C": "CN",
  11. "ST": "beijing",
  12. "L": "beijing",
  13. "O": "jdt",
  14. "OU": "iot"
  15. }
  16. ]
  17. }
  18. EOF

生成 CA 证书和私钥


点击(此处)折叠或打开

  1. # cfssl gencert -initca ca-csr.json | cfssljson -bare ca

创建etcd的TLS认证证书


点击(此处)折叠或打开

  1. # cat > etcd-csr.json <<EOF
  2. {
  3.   "CN": "etcd",
  4.   "hosts": [
  5.     "192.168.3.21",
  6.     "192.168.3.22",
  7.     "192.168.3.23",
  8.     "192.168.3.24",
  9.     "192.168.3.23",
  10.     "192.168.3.26",
  11.     "etcd1",
  12.     "etcd2",
  13.     "etcd3",
  14.     "master1",
  15.     "master2",
  16.     "master3"
  17.   ],
  18.   "key": {
  19.     "algo": "rsa",
  20.     "size": 2048
  21.   },
  22.   "names": [
  23.     {
  24.       "C": "CN",
  25.       "ST": "beijing",
  26.       "L": "beijing",
  27.       "O": "jdt",
  28.       "OU": "iot"
  29.     }
  30.   ]
  31. EOF

生成 etcd证书和私钥并分发


点击(此处)折叠或打开

  1. # cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=etcd etcd-csr.json | cfssljson -bare etcd
  2. # ansible etcd -m copy -a "src=/root/ssl/ dest=/export/Data/certs/"

ETCD安装以及配置

创建数据目录


点击(此处)折叠或打开

  1. # ansible etcd -m shell -a "mkdir -p /export/Data/etcd_data"

下载etcd并分发


点击(此处)折叠或打开

  1. # wget https://github.com/etcd-io/etcd/releases/download/v3.5.1/etcd-v3.5.1-linux-amd64.tar.gz
  2. # tar xf etcd-v3.5.1-linux-amd64.tar.gz && cd etcd-v3.5.1-linux-amd64
  3. # ansible etcd -m copy -a "src=etcd dest=/usr/bin/"
  4. # ansible etcd -m copy -a "src=etcdutl dest=/usr/bin/"
  5. # ansible etcd -m copy -a "src=etcdctl dest=/usr/bin/"
  6. # ansible etcd -m shell -a "chmod +x /usr/bin/etcd*"

配置etcd


点击(此处)折叠或打开

  1. # cat etcd_config.sh
  2. #!/bin/bash

  3. #PEER_NAME指定本节点的主机名称/域名,
  4. #PRIVATE_IP指定本节点的IP(用于后面配置文件的生成)
  5. #ETCD_CLUSTER群集列表,是所有节点信息(内容格式: 各节点名称=https://ip:端口 名称任意但要有标识性)
  6. #ETCD_INITIAL_CLUSTER_TOKEN为该etcd集群Token,同一集群token一致
  7. interface_name=`cat /proc/net/dev | sed -n '3,$p' | awk -F ':' {'print $1'} | grep -E "^ " | grep -v lo | head -n1`
  8. ipaddr=`ip a | grep $interface_name | awk '{print $2}' | awk -F"/" '{print $1}' | awk -F':' '{print $NF}'`
  9. export PEER_NAME=`hostname`
  10. export PRIVATE_IP=`echo $ipaddr | tr -d '\r'`
  11. export ETCD_CLUSTER="etcd1="
  12. export ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-1"


  13. cat > /etc/systemd/system/etcd.service <<EOF
  14. [Unit]
  15. Description=etcd
  16. Documentation=https://github.com/coreos/etcd
  17. Conflicts=etcd.service

  18. [Service]
  19. Type=notify
  20. Restart=always
  21. RestartSec=5s
  22. LimitNOFILE=65536
  23. TimeoutStartSec=0

  24. ExecStart=/usr/bin/etcd --name ${PEER_NAME} \
  25.     --data-dir /export/Data/etcd_data\
  26.     --listen-client-urls https://${PRIVATE_IP}:2379 \
  27.     --advertise-client-urls https://${PRIVATE_IP}:2379 \
  28.     --listen-peer-urls https://${PRIVATE_IP}:2380 \
  29.     --initial-advertise-peer-urls https://${PRIVATE_IP}:2380 \
  30.     --cert-file=/export/Data/certs/etcd.pem \
  31.     --key-file=/export/Data/certs/etcd-key.pem \
  32.     --client-cert-auth \
  33.     --trusted-ca-file=/export/Data/certs/ca.pem \
  34.     --peer-cert-file=/export/Data/certs/etcd.pem \
  35.     --peer-key-file=/export/Data/certs/etcd-key.pem \
  36.     --peer-client-cert-auth \
  37.     --peer-trusted-ca-file=/export/Data/certs/ca.pem \
  38.     --initial-cluster ${ETCD_CLUSTER} \
  39.     --initial-cluster-token etcd-cluster-1 \
  40.     --initial-cluster-state new

  41. [Install]
  42. WantedBy=multi-user.target

  43. EOF


点击(此处)折叠或打开

  1. # ansible etcd -m script -a "/root/etcd_config.sh"

启动ETCD


点击(此处)折叠或打开

  1. # ansible etcd -m shell -a "systemctl daemon-reload"
  2. # ansible etcd -m service -a 'name=etcd state=started'
  3. # ansible etcd -m shell -a "systemctl enable etcd"

校验ETCD

注: ansible节点执行,需安装 etcdctl# cat

点击(此处)折叠或打开

  1. # cat check_etcd.sh
  2. #!/bin/bash

  3. HOST1=192.168.3.21
  4. HOST2=192.168.3.22
  5. HOST3=192.168.3.23
  6. ENDPOINTS=$HOST1:2379,$HOST2:2379,$HOST3:2379
  7. #因为开启了证书验证,因此执行命令需加上证书
  8. KEY="--cacert=/root/ssl/ca.pem \
  9. --cert=/root/ssl/etcd.pem \
  10. --key=/root/ssl/etcd-key.pem"


  11. #etcd集群健康信息
  12. etcdctl --endpoints=$ENDPOINTS $KEY endpoint health

  13. #etcd集群状态信息
  14. etcdctl --endpoints=$ENDPOINTS $KEY --write-out=table endpoint status

  15. #etcd集群成员信息
  16. etcdctl --endpoints=$ENDPOINTS $KEY member list -w table

点击(此处)折叠或打开

  1. # sh check_etcd.sh
  2. 192.168.3.22:2379 is healthy: successfully committed proposal: took = 6.670434ms
  3. 192.168.3.23:2379 is healthy: successfully committed proposal: took = 7.021894ms
  4. 192.168.3.21:2379 is healthy: successfully committed proposal: took = 6.938656ms
  5. +-------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  6. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
  7. +-------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  8. | 192.168.3.21:2379 | a30c90f91c6bc0bf | 3.5.1 | 20 kB | false | false | 2 | 23 | 23 | |
  9. | 192.168.3.22:2379 | 877407b6419f0fed | 3.5.1 | 20 kB | true | false | 2 | 23 | 23 | |
  10. | 192.168.3.23:2379 | 75b3a36457698e9a | 3.5.1 | 37 kB | false | false | 2 | 23 | 23 | |
  11. +-------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  12. +------------------+---------+-------+---------------------------+---------------------------+------------+
  13. | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
  14. +------------------+---------+-------+---------------------------+---------------------------+------------+
  15. | 75b3a36457698e9a | started | etcd3 | https://192.168.3.23:2380 | https://192.168.3.23:2379 | false |
  16. | 877407b6419f0fed | started | etcd2 | https://192.168.3.22:2380 | https://192.168.3.22:2379 | false |
  17. | a30c90f91c6bc0bf | started | etcd1 | https://192.168.3.21:2380 | https://192.168.3.21:2379 | false |
  18. +------------------+---------+-------+---------------------------+---------------------------+------------+

安装配置 CRI-O

安装CRI-O


点击(此处)折叠或打开

  1. # cat get_cri-o.sh
  2. #!/bin/bash
  3. VERSION=1.22
  4. sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/CentOS_7/devel:kubic:libcontainers:stable.repo
  5. sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:${VERSION}.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:${VERSION}/CentOS_7/devel:kubic:libcontainers:stable:cri-o:${VERSION}.repo


点击(此处)折叠或打开

  1. # ansible k8s -m yum -a "name=cri-o,cri-tools state=latest"
  2. # ansible k8s -m shell -a "sudo systemctl enable --now crio"

修改cri-o 存储路径


点击(此处)折叠或打开

  1. # ansible k8s -m shell -a "sed -i -e 's?^graphroot =.*?graphroot = "/export/Data/containers/storage"?g' /etc/containers/storage.conf"

配置cgroup


点击(此处)折叠或打开

  1. # cat 02-cgroup-manager.conf
  2. [crio.runtime]
  3. conmon_cgroup = "pod"
  4. cgroup_manager = "systemd"

  5. # ansible k8s -m copy -a "src=02-cgroup-manager.conf dest=/etc/crio/crio.conf.d/"

配置镜像加速


点击(此处)折叠或打开

  1. # cat images_mirr.sh
  2. #!/bin/bash
  3. cat >> /etc/containers/registries.conf << EOF
  4. [[registry]]
  5. prefix = "docker.io"
  6. location = "hub-mirror.c.163.com"

  7. [[registry.mirror]]
  8. prefix = "docker.io"
  9. location = "hub-mirror.c.163.com"
  10. EOF

点击(此处)折叠或打开

  1. # ansible k8s -m script -a "/root/images_mirr.sh"
  2. # ansible k8s -m service -a 'name=crio state=restarted'

配置LB

公有云使用负载均衡代替


高可用LB后续更新,暂用nginx代替


以下操作LB节点执行

点击(此处)折叠或打开

  1. [root@lb ~]# yum -y install epel-release.noarch
  2. [root@lb ~]# yum -y install nginx nginx-mod-stream
nginx 配置文件中加入以下配置

点击(此处)折叠或打开

  1. stream {
  2.   log_format main '$remote_addr [$time_local]'
  3.                     '$protocol $status $bytes_sent $bytes_received'
  4.                     '$session_time';
  5.   server {
  6.     listen 16443;
  7.     proxy_pass kubeapi;
  8.     access_log /var/log/nginx/access.log main;
  9.   }
  10.   upstream kubeapi {
  11.     server 192.168.3.24:6443;
  12.     server 192.168.3.25:6443;
  13.     server 192.168.3.26:6443;
  14.   }
  15. }


部署k8s

安装kubeadm、kubelet


点击(此处)折叠或打开

  1. # cat kube.sh
  2. #!/bin/bash
  3. cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
  4. [kubernetes]
  5. name=Kubernetes
  6. baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
  7. enabled=1
  8. gpgcheck=1
  9. repo_gpgcheck=1
  10. gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
  11. exclude=kubelet kubeadm kubectl
  12. EOF
  13. yum install -y kubelet-1.22.3-0 kubeadm-1.22.3-0 kubectl-1.22.3-0 --disableexcludes=kubernetes

  14. sudo systemctl enable --now kubelet


  15. # ansible k8s -m script -a "/root/kube.sh"

分发etcd证书


点击(此处)折叠或打开

  1. # ansible k8s -m shell -a "mkdir -p /export/Data/certs/"

配置kubelet


点击(此处)折叠或打开

  1. # cat kubelet_conf.sh
  2. #!/bin/bash

  3. cat > /etc/sysconfig/kubelet <<EOF
  4. KUBELET_EXTRA_ARGS=--container-runtime=remote --cgroup-driver=systemd --container-runtime-endpoint='unix:///var/run/crio/crio.sock' --runtime-request-timeout=5m
  5. EOF

  6. # ansible k8s -m script -a "/root/kubelet_conf.sh"
  7. # ansible k8s -m service -a 'name=kubelet state=restarted'

初始{BANNED}中国{BANNED}中国第一个master节点


点击(此处)折叠或打开

  1. # cat kubeadm_config.yaml
  2. apiVersion: kubeadm.k8s.io/v1beta2
  3. kind: ClusterConfiguration
  4. kubernetesVersion: v1.22.3
  5. imageRepository: registry.aliyuncs.com/google_containers
  6. controlPlaneEndpoint: "192.168.3.29:16443"
  7. networking:
  8.   serviceSubnet: "10.96.0.0/16"
  9.   podSubnet: "172.16.0.0/16"
  10.   dnsDomain: "cluster.local"
  11. dns:
  12.   type: "CoreDNS"
  13. etcd:
  14.   external:
  15.      endpoints:
  16.      - https://192.168.3.21:2379
  17.      - https://192.168.3.22:2379
  18.      - https://192.168.3.23:2379
  19.      caFile: /export/Data/certs/ca.pem
  20.      certFile: /export/Data/certs/etcd.pem
  21.      keyFile: /export/Data/certs/etcd-key.pem
  22. ---
  23. apiVersion: kubelet.config.k8s.io/v1beta1
  24. kind: KubeletConfiguration
  25. cgroupDriver: systemd

  26. ---
  27. apiVersion: kubeproxy.config.k8s.io/v1alpha1
  28. kind: KubeProxyConfiguration
  29. mode: ipvs

点击(此处)折叠或打开

  1. # ansible 192.168.3.24 -m copy -a "src=kubeadm_config.yaml dest=/root"
  2. # ansible k8s -m copy -a "src=/root/ssl/ dest=/export/Data/certs/"
  3. # ansible 192.168.3.24 -m shell -a "kubeadm init --config=/root/kubeadm_config.yaml --upload-certs"

初始化第二个master节点

注: 密钥上步获得


点击(此处)折叠或打开

  1. # ansible 192.168.3.25 -m shell -a "kubeadm join 192.168.3.29:16443 --token de4x51.d923b7l0tbi0692t --discovery-token-ca-cert-hash sha256:b1a8f00caed912ac083d10d8ecd1e92ddf6870c768f91d4e43c91c2614e24e1a --control-plane --certificate-key 0b34ca2ebd85f99ff66b2f57b80708e2ac0368880da52a802e3feb01852f2d81"

初始化第三个master节点


点击(此处)折叠或打开

  1. # ansible 192.168.3.26 -m shell -a "kubeadm join 192.168.3.29:16443 --token de4x51.d923b7l0tbi0692t --discovery-token-ca-cert-hash sha256:b1a8f00caed912ac083d10d8ecd1e92ddf6870c768f91d4e43c91c2614e24e1a --control-plane --certificate-key 0b34ca2ebd85f99ff66b2f57b80708e2ac0368880da52a802e3feb01852f2d81"

初始化worker节点


点击(此处)折叠或打开

  1. # ansible k8s-worker -m shell -a " kubeadm join 192.168.3.29:16443 --token de4x51.d923b7l0tbi0692t --discovery-token-ca-cert-hash sha256:b1a8f00caed912ac083d10d8ecd1e92ddf6870c768f91d4e43c91c2614e24e1a"

初始化kubectl


点击(此处)折叠或打开

  1. # mkdir -p $HOME/.kube
  2. # scp root@192.168.3.24:/etc/kubernetes/admin.conf $HOME/.kube/config
  3. # scp root@192.168.3.24:/usr/bin/kubectl /usr/bin/kubectl

验证kubelet


点击(此处)折叠或打开

  1. [root@deploy ~]# kubectl get node
  2. NAME STATUS ROLES AGE VERSION
  3. master1 Ready control-plane,master 41m v1.22.3
  4. master2 Ready control-plane,master 13m v1.22.3
  5. master3 Ready control-plane,master 12m v1.22.3
  6. worker1 Ready <none> 9m18s v1.22.3
  7. worker2 Ready <none> 9m19s v1.22.3

部署网络模型

修改配置


点击(此处)折叠或打开

  1. ---
  2. # Source: calico/templates/calico-etcd-secrets.yaml
  3. # The following contains k8s Secrets for use with a TLS enabled etcd cluster.
  4. # For information on populating Secrets, see http://kubernetes.io/docs/user-guide/secrets/
  5. apiVersion: v1
  6. kind: Secret
  7. type: Opaque
  8. metadata:
  9.   name: calico-etcd-secrets
  10.   namespace: kube-system
  11. data:
  12.   # Populate the following with etcd TLS configuration if desired, but leave blank if
  13.   # not using TLS for etcd.
  14.   # The keys below should be uncommented and the values populated with the base64
  15.   # encoded contents of each file that would be associated with the TLS data.
  16.   # Example command for encoding a file contents: cat <file> | base64 -w 0
  17.   etcd-key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBNkZJNE91OUl4WU01L2IxUVBHa2RWQUF0UHc1QzA1b0MwN1Z0WGhWaWZDUzY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Z05WSFE0RUZnUVV5Z2F2NkExczdTelIKaDk3SzdxSEFmcXdlWXljd0h3WURWUjBqQkJnd0ZvQVV5Z2F2NkExczdTelJoOTdLN3FIQWZxd2VZeWN3RFFZSgpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFEQ1huN3h0VnFjT2ptTUcvUFpHYWp5UEdVTlFsKzNwaFhnYm1vZmtQMFNoCkJlVTZXbTNkOHB4WThrR0xTT2gxSzl1MlA3RnUyTzY3M21pMkdSOEJPT3NLWS9UK0p0RmlmenlmY3VGMjQ4L3QKcFFjRkNUOGw1Wjc1bXcySTRORXZJU1pnU3piWVN0SXdPU01FcFBJZWRRNzY2QUxtVGVwZXNuVll3K2U2dGlBUgpmS0lqakJEeGcrd1B4b2tseWNxWXRCQVA5dDRKMVk4Vkt6VENNelorcllweWRNNWlIaElFK3VYTlhqSXJTMURMCmxNN3JSS2crblRnRk9ma2dPQ3FaTmlZMTFzdzNWQnJUOW4rM1BhTzB2ekZqbXcrUVNxTVpTclJUS1d1V2xaSkcKT2JiUXUvcGhKdk9hZ2NBbUVXRGorNUdaZTVwS29neXlIdUVSVW0wSzYwST0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
  20. ---
  21. # Source: calico/templates/calico-config.yaml
  22. # This ConfigMap is used to configure a self-hosted Calico installation.
  23. kind: ConfigMap
  24. apiVersion: v1
  25. metadata:
  26.   name: calico-config
  27.   namespace: kube-system
  28. data:
  29.   # Configure this with the location of your etcd cluster.
  30.   etcd_endpoints: ""
  31.   # If you're using TLS enabled etcd uncomment the following.
  32.   # You must also populate the Secret below with these files.
  33.   etcd_ca: "/calico-secrets/etcd-ca" # "/calico-secrets/etcd-ca"
  34.   etcd_cert: "/calico-secrets/etcd-cert" # "/calico-secrets/etcd-cert"
  35.   etcd_key: "/calico-secrets/etcd-key" # "/calico-secrets/etcd-key"
  36.   # Typha is disabled.
  37.   typha_service_name: "none"
  38.   # Configure the backend to use.
  39.   calico_backend: "vxlan"

  40.   # Configure the MTU to use for workload interfaces and tunnels.
  41.   # By default, MTU is auto-detected, and explicitly setting this field should not be required.
  42.   # You can override auto-detection by providing a non-zero value.
  43.   veth_mtu: "0"

  44.   # The CNI network configuration to install on each node. The special
  45.   # values in this config will be automatically populated.
  46.   cni_network_config: |-
  47.     {
  48.       "name": "k8s-pod-network",
  49.       "cniVersion": "0.3.1",
  50.       "plugins": [
  51.         {
  52.           "type": "calico",
  53.           "log_level": "info",
  54.           "log_file_path": "/var/log/calico/cni/cni.log",
  55.           "etcd_endpoints": "__ETCD_ENDPOINTS__",
  56.           "etcd_key_file": "__ETCD_KEY_FILE__",
  57.           "etcd_cert_file": "__ETCD_CERT_FILE__",
  58.           "etcd_ca_cert_file": "__ETCD_CA_CERT_FILE__",
  59.           "mtu": __CNI_MTU__,
  60.           "ipam": {
  61.               "type": "calico-ipam"
  62.           },
  63.           "policy": {
  64.               "type": "k8s"
  65.           },
  66.           "kubernetes": {
  67.               "kubeconfig": "__KUBECONFIG_FILEPATH__"
  68.           }
  69.         },
  70.         {
  71.           "type": "portmap",
  72.           "snat": true,
  73.           "capabilities": {"portMappings": true}
  74.         },
  75.         {
  76.           "type": "bandwidth",
  77.           "capabilities": {"bandwidth": true}
  78.         }
  79.       ]
  80.     }

  81. ---
  82. # Source: calico/templates/calico-kube-controllers-rbac.yaml

  83. # Include a clusterrole for the kube-controllers component,
  84. # and bind it to the calico-kube-controllers serviceaccount.
  85. kind: ClusterRole
  86. apiVersion: rbac.authorization.k8s.io/v1
  87. metadata:
  88.   name: calico-kube-controllers
  89. rules:
  90.   # Pods are monitored for changing labels.
  91.   # The node controller monitors Kubernetes nodes.
  92.   # Namespace and serviceaccount labels are used for policy.
  93.   - apiGroups: [""]
  94.     resources:
  95.       - pods
  96.       - nodes
  97.       - namespaces
  98.       - serviceaccounts
  99.     verbs:
  100.       - watch
  101.       - list
  102.       - get
  103.   # Watch for changes to Kubernetes NetworkPolicies.
  104.   - apiGroups: ["networking.k8s.io"]
  105.     resources:
  106.       - networkpolicies
  107.     verbs:
  108.       - watch
  109.       - list
  110. ---
  111. kind: ClusterRoleBinding
  112. apiVersion: rbac.authorization.k8s.io/v1
  113. metadata:
  114.   name: calico-kube-controllers
  115. roleRef:
  116.   apiGroup: rbac.authorization.k8s.io
  117.   kind: ClusterRole
  118.   name: calico-kube-controllers
  119. subjects:
  120. - kind: ServiceAccount
  121.   name: calico-kube-controllers
  122.   namespace: kube-system
  123. ---

  124. ---
  125. # Source: calico/templates/calico-node-rbac.yaml
  126. # Include a clusterrole for the calico-node DaemonSet,
  127. # and bind it to the calico-node serviceaccount.
  128. kind: ClusterRole
  129. apiVersion: rbac.authorization.k8s.io/v1
  130. metadata:
  131.   name: calico-node
  132. rules:
  133.   # The CNI plugin needs to get pods, nodes, and namespaces.
  134.   - apiGroups: [""]
  135.     resources:
  136.       - pods
  137.       - nodes
  138.       - namespaces
  139.     verbs:
  140.       - get
  141.   # EndpointSlices are used for Service-based network policy rule
  142.   # enforcement.
  143.   - apiGroups: ["discovery.k8s.io"]
  144.     resources:
  145.       - endpointslices
  146.     verbs:
  147.       - watch
  148.       - list
  149.   - apiGroups: [""]
  150.     resources:
  151.       - endpoints
  152.       - services
  153.     verbs:
  154.       # Used to discover service IPs for advertisement.
  155.       - watch
  156.       - list
  157.   # Pod CIDR auto-detection on kubeadm needs access to config maps.
  158.   - apiGroups: [""]
  159.     resources:
  160.       - configmaps
  161.     verbs:
  162.       - get
  163.   - apiGroups: [""]
  164.     resources:
  165.       - nodes/status
  166.     verbs:
  167.       # Needed for clearing NodeNetworkUnavailable flag.
  168.       - patch

  169. ---
  170. apiVersion: rbac.authorization.k8s.io/v1
  171. kind: ClusterRoleBinding
  172. metadata:
  173.   name: calico-node
  174. roleRef:
  175.   apiGroup: rbac.authorization.k8s.io
  176.   kind: ClusterRole
  177.   name: calico-node
  178. subjects:
  179. - kind: ServiceAccount
  180.   name: calico-node
  181.   namespace: kube-system

  182. ---
  183. # Source: calico/templates/calico-node.yaml
  184. # This manifest installs the calico-node container, as well
  185. # as the CNI plugins and network config on
  186. # each master and worker node in a Kubernetes cluster.
  187. kind: DaemonSet
  188. apiVersion: apps/v1
  189. metadata:
  190.   name: calico-node
  191.   namespace: kube-system
  192.   labels:
  193.     k8s-app: calico-node
  194. spec:
  195.   selector:
  196.     matchLabels:
  197.       k8s-app: calico-node
  198.   updateStrategy:
  199.     type: RollingUpdate
  200.     rollingUpdate:
  201.       maxUnavailable: 1
  202.   template:
  203.     metadata:
  204.       labels:
  205.         k8s-app: calico-node
  206.     spec:
  207.       nodeSelector:
  208.         kubernetes.io/os: linux
  209.       hostNetwork: true
  210.       tolerations:
  211.         # Make sure calico-node gets scheduled on all nodes.
  212.         - effect: NoSchedule
  213.           operator: Exists
  214.         # Mark the pod as a critical add-on for rescheduling.
  215.         - key: CriticalAddonsOnly
  216.           operator: Exists
  217.         - effect: NoExecute
  218.           operator: Exists
  219.       serviceAccountName: calico-node
  220.       # Minimize downtime during a rolling upgrade or deletion; tell Kubernetes to do a "force
  221.       # deletion":
  222.       terminationGracePeriodSeconds: 0
  223.       priorityClassName: system-node-critical
  224.       initContainers:
  225.         # This container installs the CNI binaries
  226.         # and CNI network config file on each node.
  227.         - name: install-cni
  228.           image: docker.mirrors.ustc.edu.cn/calico/cni:v3.21.0
  229.           command: ["/opt/cni/bin/install"]
  230.           envFrom:
  231.           - configMapRef:
  232.               # Allow KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT to be overridden for eBPF mode.
  233.               name: kubernetes-services-endpoint
  234.               optional: true
  235.           env:
  236.             # Name of the CNI config file to create.
  237.             - name: CNI_CONF_NAME
  238.               value: "10-calico.conflist"
  239.             # The CNI network config to install on each node.
  240.             - name: CNI_NETWORK_CONFIG
  241.               valueFrom:
  242.                 configMapKeyRef:
  243.                   name: calico-config
  244.                   key: cni_network_config
  245.             # The location of the etcd cluster.
  246.             - name: ETCD_ENDPOINTS
  247.               valueFrom:
  248.                 configMapKeyRef:
  249.                   name: calico-config
  250.                   key: etcd_endpoints
  251.             # CNI MTU Config variable
  252.             - name: CNI_MTU
  253.               valueFrom:
  254.                 configMapKeyRef:
  255.                   name: calico-config
  256.                   key: veth_mtu
  257.             # Prevents the container from sleeping forever.
  258.             - name: SLEEP
  259.               value: "false"
  260.           volumeMounts:
  261.             - mountPath: /host/opt/cni/bin
  262.               name: cni-bin-dir
  263.             - mountPath: /host/etc/cni/net.d
  264.               name: cni-net-dir
  265.             - mountPath: /calico-secrets
  266.               name: etcd-certs
  267.           securityContext:
  268.             privileged: true
  269.         # Adds a Flex Volume Driver that creates a per-pod Unix Domain Socket to allow Dikastes
  270.         # to communicate with Felix over the Policy Sync API.
  271.         - name: flexvol-driver
  272.           image: docker.mirrors.ustc.edu.cn/calico/pod2daemon-flexvol:v3.21.0
  273.           volumeMounts:
  274.           - name: flexvol-driver-host
  275.             mountPath: /host/driver
  276.           securityContext:
  277.             privileged: true
  278.       containers:
  279.         # Runs calico-node container on each Kubernetes node. This
  280.         # container programs network policy and routes on each
  281.         # host.
  282.         - name: calico-node
  283.           image: docker.mirrors.ustc.edu.cn/calico/node:v3.21.0
  284.           envFrom:
  285.           - configMapRef:
  286.               # Allow KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT to be overridden for eBPF mode.
  287.               name: kubernetes-services-endpoint
  288.               optional: true
  289.           env:
  290.             # The location of the etcd cluster.
  291.             - name: ETCD_ENDPOINTS
  292.               valueFrom:
  293.                 configMapKeyRef:
  294.                   name: calico-config
  295.                   key: etcd_endpoints
  296.             # Location of the CA certificate for etcd.
  297.             - name: ETCD_CA_CERT_FILE
  298.               valueFrom:
  299.                 configMapKeyRef:
  300.                   name: calico-config
  301.                   key: etcd_ca
  302.             # Location of the client key for etcd.
  303.             - name: ETCD_KEY_FILE
  304.               valueFrom:
  305.                 configMapKeyRef:
  306.                   name: calico-config
  307.                   key: etcd_key
  308.             # Location of the client certificate for etcd.
  309.             - name: ETCD_CERT_FILE
  310.               valueFrom:
  311.                 configMapKeyRef:
  312.                   name: calico-config
  313.                   key: etcd_cert
  314.             # Set noderef for node controller.
  315.             - name: CALICO_K8S_NODE_REF
  316.               valueFrom:
  317.                 fieldRef:
  318.                   fieldPath: spec.nodeName
  319.             # Choose the backend to use.
  320.             - name: CALICO_NETWORKING_BACKEND
  321.               valueFrom:
  322.                 configMapKeyRef:
  323.                   name: calico-config
  324.                   key: calico_backend
  325.             # Cluster type to identify the deployment type
  326.             - name: CLUSTER_TYPE
  327.               value: "k8s,bgp"
  328.             # Auto-detect the BGP IP address.
  329.             - name: IP
  330.               value: "autodetect"
  331.             # Enable IPIP
  332.             - name: CALICO_IPV4POOL_IPIP
  333.               value: "Never"
  334.             # Enable or Disable VXLAN on the default IP pool.
  335.             - name: CALICO_IPV4POOL_VXLAN
  336.               value: "Always"
  337.             # Set MTU for tunnel device used if ipip is enabled
  338.             - name: FELIX_IPINIPMTU
  339.               valueFrom:
  340.                 configMapKeyRef:
  341.                   name: calico-config
  342.                   key: veth_mtu
  343.             # Set MTU for the VXLAN tunnel device.
  344.             - name: FELIX_VXLANMTU
  345.               valueFrom:
  346.                 configMapKeyRef:
  347.                   name: calico-config
  348.                   key: veth_mtu
  349.             # Set MTU for the Wireguard tunnel device.
  350.             - name: FELIX_WIREGUARDMTU
  351.               valueFrom:
  352.                 configMapKeyRef:
  353.                   name: calico-config
  354.                   key: veth_mtu
  355.             # The default IPv4 pool to create on startup if none exists. Pod IPs will be
  356.             # chosen from this range. Changing this value after installation will have
  357.             # no effect. This should fall within `--cluster-cidr`.
  358.             - name: CALICO_IPV4POOL_CIDR
  359.               value: "172.16.0.0/16"
  360.             # Disable file logging so `kubectl logs` works.
  361.             - name: CALICO_DISABLE_FILE_LOGGING
  362.               value: "true"
  363.             # Set Felix endpoint to host default action to ACCEPT.
  364.             - name: FELIX_DEFAULTENDPOINTTOHOSTACTION
  365.               value: "ACCEPT"
  366.             # Disable IPv6 on Kubernetes.
  367.             - name: FELIX_IPV6SUPPORT
  368.               value: "false"
  369.             - name: FELIX_HEALTHENABLED
  370.               value: "true"
  371.           securityContext:
  372.             privileged: true
  373.           resources:
  374.             requests:
  375.               cpu: 250m
  376.           lifecycle:
  377.             preStop:
  378.               exec:
  379.                 command:
  380.                 - /bin/calico-node
  381.                 - -shutdown
  382.           livenessProbe:
  383.             exec:
  384.               command:
  385.               - /bin/calico-node
  386.               - -felix-live
  387.               #- -bird-live
  388.             periodSeconds: 10
  389.             initialDelaySeconds: 10
  390.             failureThreshold: 6
  391.             timeoutSeconds: 10
  392.           readinessProbe:
  393.             exec:
  394.               command:
  395.               - /bin/calico-node
  396.               - -felix-ready
  397.               #- -bird-ready
  398.             periodSeconds: 10
  399.             timeoutSeconds: 10
  400.           volumeMounts:
  401.             # For maintaining CNI plugin API credentials.
  402.             - mountPath: /host/etc/cni/net.d
  403.               name: cni-net-dir
  404.               readOnly: false
  405.             - mountPath: /lib/modules
  406.               name: lib-modules
  407.               readOnly: true
  408.             - mountPath: /run/xtables.lock
  409.               name: xtables-lock
  410.               readOnly: false
  411.             - mountPath: /var/run/calico
  412.               name: var-run-calico
  413.               readOnly: false
  414.             - mountPath: /var/lib/calico
  415.               name: var-lib-calico
  416.               readOnly: false
  417.             - mountPath: /calico-secrets
  418.               name: etcd-certs
  419.             - name: policysync
  420.               mountPath: /var/run/nodeagent
  421.             # For eBPF mode, we need to be able to mount the BPF filesystem at /sys/fs/bpf so we mount in the
  422.             # parent directory.
  423.             - name: sysfs
  424.               mountPath: /sys/fs/
  425.               # Bidirectional means that, if we mount the BPF filesystem at /sys/fs/bpf it will propagate to the host.
  426.               # If the host is known to mount that filesystem already then Bidirectional can be omitted.
  427.               mountPropagation: Bidirectional
  428.             - name: cni-log-dir
  429.               mountPath: /var/log/calico/cni
  430.               readOnly: true
  431.       volumes:
  432.         # Used by calico-node.
  433.         - name: lib-modules
  434.           hostPath:
  435.             path: /lib/modules
  436.         - name: var-run-calico
  437.           hostPath:
  438.             path: /var/run/calico
  439.         - name: var-lib-calico
  440.           hostPath:
  441.             path: /var/lib/calico
  442.         - name: xtables-lock
  443.           hostPath:
  444.             path: /run/xtables.lock
  445.             type: FileOrCreate
  446.         - name: sysfs
  447.           hostPath:
  448.             path: /sys/fs/
  449.             type: DirectoryOrCreate
  450.         # Used to install CNI.
  451.         - name: cni-bin-dir
  452.           hostPath:
  453.             path: /opt/cni/bin
  454.         - name: cni-net-dir
  455.           hostPath:
  456.             path: /etc/cni/net.d
  457.         # Used to access CNI logs.
  458.         - name: cni-log-dir
  459.           hostPath:
  460.             path: /var/log/calico/cni
  461.         # Mount in the etcd TLS secrets with mode 400.
  462.         # See
  463.         - name: etcd-certs
  464.           secret:
  465.             secretName: calico-etcd-secrets
  466.             defaultMode: 0400
  467.         # Used to create per-pod Unix Domain Sockets
  468.         - name: policysync
  469.           hostPath:
  470.             type: DirectoryOrCreate
  471.             path: /var/run/nodeagent
  472.         # Used to install Flex Volume Driver
  473.         - name: flexvol-driver-host
  474.           hostPath:
  475.             type: DirectoryOrCreate
  476.             path: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/nodeagent~uds
  477. ---

  478. apiVersion: v1
  479. kind: ServiceAccount
  480. metadata:
  481.   name: calico-node
  482.   namespace: kube-system

  483. ---
  484. # Source: calico/templates/calico-kube-controllers.yaml
  485. # See
  486. apiVersion: apps/v1
  487. kind: Deployment
  488. metadata:
  489.   name: calico-kube-controllers
  490.   namespace: kube-system
  491.   labels:
  492.     k8s-app: calico-kube-controllers
  493. spec:
  494.   # The controllers can only have a single active instance.
  495.   replicas: 1
  496.   selector:
  497.     matchLabels:
  498.       k8s-app: calico-kube-controllers
  499.   strategy:
  500.     type: Recreate
  501.   template:
  502.     metadata:
  503.       name: calico-kube-controllers
  504.       namespace: kube-system
  505.       labels:
  506.         k8s-app: calico-kube-controllers
  507.     spec:
  508.       nodeSelector:
  509.         kubernetes.io/os: linux
  510.       tolerations:
  511.         # Mark the pod as a critical add-on for rescheduling.
  512.         - key: CriticalAddonsOnly
  513.           operator: Exists
  514.         - key: node-role.kubernetes.io/master
  515.           effect: NoSchedule
  516.       serviceAccountName: calico-kube-controllers
  517.       priorityClassName: system-cluster-critical
  518.       # The controllers must run in the host network namespace so that
  519.       # it isn't governed by policy that would prevent it from working.
  520.       hostNetwork: true
  521.       containers:
  522.         - name: calico-kube-controllers
  523.           image: docker.mirrors.ustc.edu.cn/calico/kube-controllers:v3.21.0
  524.           env:
  525.             # The location of the etcd cluster.
  526.             - name: ETCD_ENDPOINTS
  527.               valueFrom:
  528.                 configMapKeyRef:
  529.                   name: calico-config
  530.                   key: etcd_endpoints
  531.             # Location of the CA certificate for etcd.
  532.             - name: ETCD_CA_CERT_FILE
  533.               valueFrom:
  534.                 configMapKeyRef:
  535.                   name: calico-config
  536.                   key: etcd_ca
  537.             # Location of the client key for etcd.
  538.             - name: ETCD_KEY_FILE
  539.               valueFrom:
  540.                 configMapKeyRef:
  541.                   name: calico-config
  542.                   key: etcd_key
  543.             # Location of the client certificate for etcd.
  544.             - name: ETCD_CERT_FILE
  545.               valueFrom:
  546.                 configMapKeyRef:
  547.                   name: calico-config
  548.                   key: etcd_cert
  549.             # Choose which controllers to run.
  550.             - name: ENABLED_CONTROLLERS
  551.               value: policy,namespace,serviceaccount,workloadendpoint,node
  552.           volumeMounts:
  553.             # Mount in the etcd TLS secrets.
  554.             - mountPath: /calico-secrets
  555.               name: etcd-certs
  556.           livenessProbe:
  557.             exec:
  558.               command:
  559.               - /usr/bin/check-status
  560.               - -l
  561.             periodSeconds: 10
  562.             initialDelaySeconds: 10
  563.             failureThreshold: 6
  564.             timeoutSeconds: 10
  565.           readinessProbe:
  566.             exec:
  567.               command:
  568.               - /usr/bin/check-status
  569.               - -r
  570.             periodSeconds: 10
  571.       volumes:
  572.         # Mount in the etcd TLS secrets with mode 400.
  573.         # See https://kubernetes.io/docs/concepts/configuration/secret/
  574.         - name: etcd-certs
  575.           secret:
  576.             secretName: calico-etcd-secrets
  577.             defaultMode: 0440

  578. ---

  579. apiVersion: v1
  580. kind: ServiceAccount
  581. metadata:
  582.   name: calico-kube-controllers
  583.   namespace: kube-system

  584. ---

  585. # This manifest creates a Pod Disruption Budget for Controller to allow K8s Cluster Autoscaler to evict

  586. apiVersion: policy/v1beta1
  587. kind: PodDisruptionBudget
  588. metadata:
  589.   name: calico-kube-controllers
  590.   namespace: kube-system
  591.   labels:
  592.     k8s-app: calico-kube-controllers
  593. spec:
  594.   maxUnavailable: 1
  595.   selector:
  596.     matchLabels:
  597.       k8s-app: calico-kube-controllers

  598. ---
  599. # Source: calico/templates/calico-typha.yaml

  600. ---
  601. # Source: calico/templates/configure-canal.yaml

  602. ---
  603. # Source: calico/templates/kdd-crds.yaml

安装calico


点击(此处)折叠或打开

  1. # kubectl apply -f calico-etcd.yaml

验证集群


点击(此处)折叠或打开

  1. [root@deploy ~]# kubectl get pod -n kube-system
  2. NAME READY STATUS RESTARTS AGE
  3. calico-kube-controllers-9767fc4b9-tk9fb 1/1 Running 0 6m56s
  4. calico-node-5mc9h 1/1 Running 0 6m56s
  5. calico-node-dswmp 1/1 Running 0 6m56s
  6. calico-node-qht2s 1/1 Running 0 6m56s
  7. calico-node-sdrcg 1/1 Running 0 6m56s
  8. calico-node-x58lj 1/1 Running 0 6m56s
  9. coredns-7f6cbbb7b8-fc8rd 1/1 Running 0 61m
  10. coredns-7f6cbbb7b8-qvw2m 1/1 Running 0 61m
  11. kube-apiserver-master1 1/1 Running 2 94m
  12. kube-apiserver-master2 1/1 Running 0 66m
  13. kube-apiserver-master3 1/1 Running 0 64m
  14. kube-controller-manager-master1 1/1 Running 2 94m
  15. kube-controller-manager-master2 1/1 Running 0 66m
  16. kube-controller-manager-master3 1/1 Running 0 64m
  17. kube-proxy-bscfn 1/1 Running 0 62m
  18. kube-proxy-f2fpb 1/1 Running 0 64m
  19. kube-proxy-kt7nl 1/1 Running 0 66m
  20. kube-proxy-lzww8 1/1 Running 0 62m
  21. kube-proxy-zn6gj 1/1 Running 2 94m
  22. kube-scheduler-master1 1/1 Running 2 94m
  23. kube-scheduler-master2 1/1 Running 0 66m
  24. kube-scheduler-master3 1/1 Running 0 64m

问题与解决

1 、 kubelet日报错 failed to get cgroup stats for "/system.slice/kubelet.service"


点击(此处)折叠或打开

  1. 11月 18 09:00:42 master1 kubelet[2424]: E1118 09:00:42.948672 2424 summary_sys_containers.go:47] "Failed to get system container stats" err="failed to get cgroup stats for \"/system.slice/kubelet.service\": failed to get container info for \"/system.slice/kubelet.service\": unknown container \"/system.slice/kubelet.service\"" containerName="/system.slice/kubelet.service"
  2. 11月 18 09:00:52 master1 kubelet[2424]: E1118 09:00:52.956142 2424 summary_sys_containers.go:47] "Failed to get system container stats" err="failed to get cgroup stats for \"/system.slice/kubelet.service\": failed to get container info for \"/system.slice/kubelet.service\": unknown container \"/system.slice/kubelet.service\"" containerName="/system.slice/kubelet.service"
  3. 11月 18 09:01:02 master1 kubelet[2424]: E1118 09:01:02.961022 2424 summary_sys_containers.go:47] "Failed to get system container stats" err="failed to get cgroup stats for \"/system.slice/kubelet.service\": failed to get container info for \"/system.slice/kubelet.service\": unknown container \"/system.slice/kubelet.service\"" containerName="/system.slice/kubelet.service"
  4. 11月 18 09:01:12 master1 kubelet[2424]: E1118 09:01:12.966033 2424 summary_sys_containers.go:47] "Failed to get system container stats" err="failed to get cgroup stats for \"/system.slice/kubelet.service\": failed to get container info for \"/system.slice/kubelet.service\": unknown container \"/system.slice/kubelet.service\"" containerName="/system.slice/kubelet.service"
  5. 11月 18 09:01:22 master1 kubelet[2424]: E1118 09:01:22.970644 2424 summary_sys_containers.go:47] "Failed to get system container stats" err="failed to get cgroup stats for \"/system.slice/kubelet.service\": failed to get container info for \"/system.slice/kubelet.service\": unknown container \"/system.slice/kubelet.service\"" containerName="/system.slice/kubelet.service"

解决方案

配置文件中写入 CPUAccounting=true 与 MemoryAccounting=true


点击(此处)折叠或打开

  1. [root@master2 ~]# cat /lib/systemd/system/kubelet.service.d/10-kubeadm.conf
  2. # Note: This dropin only works with kubeadm and kubelet v1.11+
  3. [Service]
  4. CPUAccounting=true
  5. MemoryAccounting=true
  6. Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
  7. Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
  8. # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
  9. EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
  10. # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
  11. # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
  12. EnvironmentFile=-/etc/sysconfig/kubelet
  13. ExecStart=
  14. ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

2、kubectl get cs 提示 dial tcp 127.0.0.1:10251: connect: connection refused


点击(此处)折叠或打开

  1. [root@deploy ~]# kubectl get cs
  2. Warning: v1 ComponentStatus is deprecated in v1.19+
  3. NAME STATUS MESSAGE ERROR
  4. scheduler Unhealthy Get "": dial tcp 127.0.0.1:10251: connect: connection refused
  5. etcd-1 Healthy {"health":"true","reason":""}
  6. controller-manager Healthy ok
  7. etcd-0 Healthy {"health":"true","reason":""}
  8. etcd-2 Healthy {"health":"true","reason":""}

解决方案

注释 port=0


点击(此处)折叠或打开

  1. [root@master1 ~]# cat /etc/kubernetes/manifests/kube-scheduler.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5.   creationTimestamp: null
  6.   labels:
  7.     component: kube-scheduler
  8.     tier: control-plane
  9.   name: kube-scheduler
  10.   namespace: kube-system
  11. spec:
  12.   containers:
  13.   - command:
  14.     - kube-scheduler
  15.     - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
  16.     - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
  17.     - --bind-address=127.0.0.1
  18.     - --kubeconfig=/etc/kubernetes/scheduler.conf
  19.     - --leader-elect=true
  20. # - --port=0
  21.     image: registry.aliyuncs.com/google_containers/kube-scheduler:v1.22.3
  22.     imagePullPolicy: IfNotPresent

点击(此处)折叠或打开

  1. [root@deploy ~]# kubectl get cs
  2. Warning: v1 ComponentStatus is deprecated in v1.19+
  3. NAME STATUS MESSAGE ERROR
  4. scheduler Healthy ok
  5. controller-manager Healthy ok
  6. etcd-1 Healthy {"health":"true","reason":""}
  7. etcd-2 Healthy {"health":"true","reason":""}
  8. etcd-0 Healthy {"health":"true","reason":""}
作者:宗庄凯

阅读(1260) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~