基于ubuntu containerd 部署kubernetes v1.30.3

基于ubuntu containerd 部署kubernetes v1.30.3

软件版本
ubuntu 22.04 LTS
containerd 1.7.17
kubernetes v1.30.1

一,基础配置
1.1配置hosts

92.168.2.63 k8s-master01【Master】
92.168.2.64 k8s-node01 【Node】
92.168.2.65 k8s-node02 【Node】
92.168.2.67 k8s-node03 【Node】

关闭swap
swapoff -a

1.2 containerd 依赖配置
创建/etc/modules-load.d/containerd.conf配置文件,确保在系统启动时自动加载所需的内核模块

cat << EOF > /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

执行以下命令使配置生效:
modprobe overlay
modprobe br_netfilter

创建/etc/sysctl.d/99-kubernetes-cri.conf配置文件:

cat << EOF > /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
user.max_user_namespaces=28633
EOF

执行以下命令使配置生效:
sysctl -p /etc/sysctl.d/99-kubernetes-cri.conf

备注:
在文件名/etc/sysctl.d/99-kubernetes-cri.conf中,“99” 代表文件的优先级或顺序。sysctl是Linux内核参数的配置工具,它可以通过修改/proc/sys/目录下的文件来设置内核参数。在/etc/sysctl.d/目录中,可以放置一系列的配置文件,以便在系统启动时自动加载这些参数。这些配置文件按照文件名的字母顺序逐个加载。数字前缀用于指定加载的顺序,较小的数字表示较高的优先级。

1.3 配置服务器支持开启ipvs的前提条件
由于ipvs已经加入到了内核的主干,所以为kube-proxy开启ipvs的前提需要加载以下的内核模块:
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4

安装ipvsadm
apt install -y ipset ipvsadm

创建/etc/modules-load.d/ipvs.conf文件,保证在节点重启后能自动加载所需模块:
cat > /etc/modules-load.d/ipvs.conf <<EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
EOF

执行以下命令使配置立即生效:
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh

使用lsmod | grep -e ip_vs -e nf_conntrack 命令查看是否已经正确加载所需的内核模块。

root@k8s-node02:~# lsmod | grep -e ip_vs -e nf_conntrack
ip_vs_sh               16384  0
ip_vs_wrr              16384  0
ip_vs_rr               16384  0
ip_vs                 212992  6 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          204800  1 ip_vs
nf_defrag_ipv6         24576  2 nf_conntrack,ip_vs
nf_defrag_ipv4         16384  1 nf_conntrack
libcrc32c              16384  5 nf_conntrack,btrfs,xfs,raid456,ip_vs

二, 部署容器运行时Containerd
在各个服务器节点上安装容器运行时Containerd。
wget https://github.com/containerd/containerd/releases/download/v1.7.17/containerd-1.7.17-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-1.7.17-linux-amd64.tar.gz

root@k8s-master01:/apps# tar Cxzvf /usr/local containerd-1.7.17-linux-amd64.tar.gz
bin/
bin/containerd-shim
bin/containerd-stress
bin/ctr
bin/containerd-shim-runc-v2
bin/containerd-shim-runc-v1
bin/containerd

wget https://github.com/opencontainers/runc/releases/download/v1.1.9/runc.amd64
nstall -m 755 riunc.amd64 /usr/local/sbin/runc

生成containerd的配置文件:

mkdir -p /etc/containerd && containerd config default > /etc/containerd/config.toml

配置各个节点上containerd的cgroup driver为systemd。

修改配置文件/etc/containerd/config.toml
vim /etc/containerd/config.toml

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
  ...
  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
    SystemdCgroup = true

再修改/etc/containerd/config.toml中的

[plugins."io.containerd.grpc.v1.cri"]
  ...
  # sandbox_image = "registry.k8s.io/pause:3.8"
  sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"

配置systemd启动containerd
参考模板,下载containerd.service单元文件
curl https://raw.githubusercontent.com/containerd/containerd/main/containerd.service >/usr/lib/systemd/system/containerd.service
systemctl daemon-reload
systemctl enable --now containerd

cat << EOF > /etc/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
EOF

配置containerd开机启动,并启动containerd,执行以下命令:
systemctl daemon-reload
systemctl enable containerd --now
systemctl status containerd

下载安装crictl工具:
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.30.3/crictl-v1.30.3-linux-amd64.tar.gz
tar -zxvf crictl-v1.30.3-linux-amd64.tar.gz
install -m 755 crictl /usr/local/bin/crictl

使用crictl测试一下,确保可以打印出版本信息并且没有错误信息输出:
crictl --runtime-endpoint=unix:///run/containerd/containerd.sock version

root@k8s-node02:/apps# crictl --runtime-endpoint=unix:///run/containerd/containerd.sock version
Version: 0.1.0
RuntimeName: containerd
RuntimeVersion: v1.7.17
RuntimeApiVersion: v1


三,部署Kubernetes
3.1 安装kubeadm和kubelet
在各节点安装kubeadm和kubelet

更新包列表

apt-get update

安装传输HTTPS所需的软件包

apt-get install -y apt-transport-https ca-certificates curl

下载用于 Kubernetes 软件包仓库的公共签名密钥。所有仓库都使用相同的签名密钥,因此你可以忽略URL中的版本:
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

添加 Kubernetes apt 仓库。

此操作会覆盖 /etc/apt/sources.list.d/kubernetes.list 中现存的所有配置。

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

更新 apt 包索引,安装 kubelet、kubeadm 和 kubectl,并锁定其版本:
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

#如遇不能正常通过HTTPS方式获取数据时,请添加环境变理
将 GNUTLS_CPUID_OVERRIDE 环境变量添加到 /etc/environment 文件中
echo ‘export GNUTLS_CPUID_OVERRIDE=0x1’ | sudo tee -a /etc/environment

退出重新登录
再执行更新包列表,安装kubelet、kubeadm和kubectl,即可成功

#防止这些包被自动升级
apt-mark hold kubelet kubeadm kubectl

swappiness参数调整,修改/etc/sysctl.d/99-kubernetes-cri.conf添加下面一行:
vm.swappiness=0

使修改配置生效
sysctl -p /etc/sysctl.d/99-kubernetes-cri.conf

3.2 使用kubeadm init初始化集群
在各节点开机启动kubelet服务:
systemctl enable kubelet.service

打印集群初始化默认的使用的配置
kubeadm config print init-defaults --component-configs KubeletConfiguration

root@k8s-master01:~# kubeadm config print init-defaults --component-configs KubeletConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 1.2.3.4
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: node
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.k8s.io
kind: ClusterConfiguration
kubernetesVersion: 1.30.3
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 0s
    cacheUnauthorizedTTL: 0s
cgroupDriver: systemd
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
containerRuntimeEndpoint: ""
cpuManagerReconcilePeriod: 0s
evictionPressureTransitionPeriod: 0s
fileCheckFrequency: 0s
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 0s
imageMaximumGCAge: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging:
  flushFrequency: 0
  options:
    json:
      infoBufferSize: "0"
    text:
      infoBufferSize: "0"
  verbosity: 0
memorySwap: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
resolvConf: /run/systemd/resolve/resolv.conf
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s

基于默认配置定制出本次使用kubeadm初始化集群所需的配置文件init.default.yaml如下:

cat init.default.yaml 
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.2.63
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: node
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: 1.30.3
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
failSwapOn: false
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs

1)定制了imageRepository为阿里云的registry,避免因gcr被墙,无法直接拉取镜像。
2)criSocket设置了容器运行时为containerd。
3)设置kubelet的cgroupDriver为systemd,设置kube-proxy代理模式为ipvs。

在开始初始化集群之前可以使用kubeadm config images pull --config kubeadm.yaml预先在各个服务器节点上拉取所k8s需要的容器镜像。

root@k8s-master01:~# kubeadm config images pull --config init.default.yaml 
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-apiserver:v1.30.3
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-controller-manager:v1.30.3
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-scheduler:v1.30.3
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-proxy:v1.30.3
[config/images] Pulled registry.aliyuncs.com/google_containers/coredns:v1.11.1
[config/images] Pulled registry.aliyuncs.com/google_containers/pause:3.9
[config/images] Pulled registry.aliyuncs.com/google_containers/etcd:3.5.12-0

初始化集群,选择192.168.2.63作为Master
#kubeadm init --config init.default.yaml

root@k8s-master01:~# kubeadm init --config init.default.yaml
[init] Using Kubernetes version: v1.30.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 [k8s-master01 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.2.63]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.2.63 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.2.63 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 "super-admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[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"
[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
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests"
[kubelet-check] Waiting for a healthy kubelet. This can take up to 4m0s
[kubelet-check] The kubelet is healthy after 506.204194ms
[api-check] Waiting for a healthy API server. This can take up to 4m0s
[api-check] The API server is healthy after 4.003227953s
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: abcdef.0123456789abcdef
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.2.63:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:afbe0c71546edbe45b005e555f61d2acb3e48913ecc66fe561b897da1c2966a8 

根据输出的内容可以看出初始化安装一个Kubernetes集群所需要的关键步骤。 其中有以下关键内容:

[certs]生成相关的各种证书
[kubeconfig]生成相关的kubeconfig文件
[kubelet-start] 生成kubelet的配置文件"/var/lib/kubelet/config.yaml"
[control-plane]使用/etc/kubernetes/manifests目录中的yaml文件创建apiserver、controller-manager、scheduler的静态pod
[bootstraptoken]生成token记录下来,后边使用kubeadm join往集群中添加节点时会用到
[addons]安装基本插件:CoreDNS, kube-proxy

下面的命令是配置常规用户如何使用kubectl访问集群:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config

最节点加入集群的命令:
kubeadm join 92.168.2.63:6443 --token zqgy73.8i3j79q5v29wd55l
–discovery-token-ca-cert-hash sha256:c9291f9bc916de50705cd884a758c3866ceab979851c5629d2d557e36dd6e490

查看一下集群状态,确认个组件都处于healthy状态,结果出现了错误:

配置kubectl环境:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config

#kubectl get cs

root@k8s-node02:/apps# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE   ERROR
scheduler            Healthy   ok        
controller-manager   Healthy   ok        
etcd-0               Healthy   ok

如果集群初始化如果遇到问题,可以使用kubeadm reset命令进行清理。


四, 安装包管理器helm 3
Helm是Kubernetes的包管理器

wget https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz
tar -zxvf helm-v3.12.3-linux-amd64.tar.gz
install -m 755 linux-amd64/helm  /usr/local/bin/helm

执行helm list确认没有错误输出。

root@k8s-node02:/apps# helm list
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION

五 部署Pod Network组件Calico

kubectl apply -f https://docs.tigera.io/archive/v3.24/manifests/calico.yaml

root@k8s-node02:/apps# kubectl get pod -n kube-system | grep tigera-operator
tigera-operator-94d7f7696-rqdqf       1/1     Running   0          26s

root@k8s-node02:/apps# kubectl get pods -n calico-system
NAME                                       READY   STATUS    RESTARTS   AGE
calico-kube-controllers-7bf865655f-xt97p   1/1     Running   0          10m
calico-node-pd4jk                          1/1     Running   0          10m
calico-typha-6895676874-d6p9d              1/1     Running   0          10m
csi-node-driver-vxp62                      2/2     Running   0          10m

查看一下calico向k8s中添加的api资源:
kubectl api-resources | grep calico

root@k8s-node02:/apps# kubectl api-resources | grep calico
bgpconfigurations                                                                 crd.projectcalico.org/v1               false        BGPConfiguration
bgpfilters                                                                        crd.projectcalico.org/v1               false        BGPFilter
bgppeers                                                                          crd.projectcalico.org/v1               false        BGPPeer
blockaffinities                                                                   crd.projectcalico.org/v1               false        BlockAffinity
caliconodestatuses                                                                crd.projectcalico.org/v1               false        CalicoNodeStatus
clusterinformations                                                               crd.projectcalico.org/v1               false        ClusterInformation
felixconfigurations                                                               crd.projectcalico.org/v1               false        FelixConfiguration
globalnetworkpolicies                                                             crd.projectcalico.org/v1               false        GlobalNetworkPolicy
globalnetworksets                                                                 crd.projectcalico.org/v1               false        GlobalNetworkSet
hostendpoints                                                                     crd.projectcalico.org/v1               false        HostEndpoint
ipamblocks                                                                        crd.projectcalico.org/v1               false        IPAMBlock
ipamconfigs                                                                       crd.projectcalico.org/v1               false        IPAMConfig
ipamhandles                                                                       crd.projectcalico.org/v1               false        IPAMHandle
ippools                                                                           crd.projectcalico.org/v1               false        IPPool
ipreservations                                                                    crd.projectcalico.org/v1               false        IPReservation
kubecontrollersconfigurations                                                     crd.projectcalico.org/v1               false        KubeControllersConfiguration
networkpolicies                                                                   crd.projectcalico.org/v1               true         NetworkPolicy
networksets                                                                       crd.projectcalico.org/v1               true         NetworkSet
bgpconfigurations                 bgpconfig,bgpconfigs                            projectcalico.org/v3                   false        BGPConfiguration
bgpfilters                                                                        projectcalico.org/v3                   false        BGPFilter
bgppeers                                                                          projectcalico.org/v3                   false        BGPPeer
blockaffinities                   blockaffinity,affinity,affinities               projectcalico.org/v3                   false        BlockAffinity
caliconodestatuses                caliconodestatus                                projectcalico.org/v3                   false        CalicoNodeStatus
clusterinformations               clusterinfo                                     projectcalico.org/v3                   false        ClusterInformation
felixconfigurations               felixconfig,felixconfigs                        projectcalico.org/v3                   false        FelixConfiguration
globalnetworkpolicies             gnp,cgnp,calicoglobalnetworkpolicies            projectcalico.org/v3                   false        GlobalNetworkPolicy
globalnetworksets                                                                 projectcalico.org/v3                   false        GlobalNetworkSet
hostendpoints                     hep,heps                                        projectcalico.org/v3                   false        HostEndpoint
ipamconfigurations                ipamconfig                                      projectcalico.org/v3                   false        IPAMConfiguration
ippools                                                                           projectcalico.org/v3                   false        IPPool
ipreservations                                                                    projectcalico.org/v3                   false        IPReservation
kubecontrollersconfigurations                                                     projectcalico.org/v3                   false        KubeControllersConfiguration
networkpolicies                   cnp,caliconetworkpolicy,caliconetworkpolicies   projectcalico.org/v3                   true         NetworkPolicy
networksets                       netsets                                         projectcalico.org/v3                   true         NetworkSet
profiles                                                                          projectcalico.org/v3                   false        Profile

这些api资源是属于calico的,因此不建议使用kubectl来管理,推荐按照calicoctl来管理这些api资源。 将calicoctl安装为kubectl的插件:

cd /usr/local/bin
curl -o kubectl-calico -O -L “https://github.com/projectcalico/calicoctl/releases/download/v3.21.5/calicoctl-linux-amd64”
chmod +x kubectl-calico
验证插件正常工作:

kubectl calico -h

六,验证k8s DNS是否可用
kubectl run curl --image=radial/busyboxplus:curl -it
If you don’t see a command prompt, try pressing enter.
[ root@curl:/ ]$
进入后执行nslookup kubernetes.default确认解析正常:

root@k8s-node02:/apps# kubectl run curl --image=radial/busyboxplus:curl -it
If you don’t see a command prompt, try pressing enter.
[ root@curl:/ ]$ nslookup kubernetes.default
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local

七, 向Kubernetes集群中添加Node节点
在node节点执行如下命令:
kubeadm join 92.168.2.63:6443 --token zqgy73.8i3j79q5v29wd55l
–discovery-token-ca-cert-hash sha256:c9291f9bc916de50705cd884a758c3866ceab979851c5629d2d557e36dd6e490

root@k8s-node01:/apps# kubeadm join 92.168.2.63:6443 --token zqgy73.8i3j79q5v29wd55l \
        --discovery-token-ca-cert-hash sha256:c9291f9bc916de50705cd884a758c3866ceab979851c5629d2d557e36dd6e490 
[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 -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.

查看节点上的calico相关pod是否启动正常

kubectl get po -n calico-system -o wide

root@k8s-master:/apps# kubectl get po -n calico-system -o wide
NAME                                       READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
calico-kube-controllers-7bf865655f-xt97p   1/1     Running   0          21m     10.244.51.66   k8s-master01  <none>           <none>
calico-node-pd4jk                          1/1     Running   0          21m     92.168.2.63   k8s-master01  <none>           <none>
calico-node-pj462                          1/1     Running   0          6m7s    92.168.2.64   k8s-node01   <none>           <none>
calico-node-s2zlp                          1/1     Running   0          5m22s   92.168.2.65   k8s-node02   <none>           <none>
calico-typha-6895676874-748p5              1/1     Running   0          5m18s   92.168.2.65   k8s-node02   <none>           <none>
calico-typha-6895676874-d6p9d              1/1     Running   0          21m     92.168.2.63   k8s-master01  <none>           <none>
csi-node-driver-4fffd                      2/2     Running   0          5m22s   10.244.244.1   k8s-node02   <none>           <none>
csi-node-driver-qfg22                      2/2     Running   0          6m7s    10.244.49.65   k8s-node01   <none>           <none>
csi-node-driver-vxp62                      2/2     Running   0          21m     10.244.51.67   k8s-master01  <none>           <none

#查看节点状态
在master节点上执行命令查看集群中的节点(需要等待新加入节点上的calico-node pod启动正常):

root@k8s-master:/apps# kubectl get nodes
NAME          STATUS   ROLES           AGE     VERSION
k8s-master01  Ready    control-plane   60m     v1.30.3
k8s-node01   Ready    <none>          5m1s    v1.30.3
k8s-node02   Ready    <none>          4m16s   v1.30.3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值