目标


软件版本


参考文档

按照文档 http://timd.cn/k8s/creating-test-cluster/ 执行 1 至 4 步。


设置 Host

/etc/hosts 中添加:

192.168.56.101 k8s-101
192.168.56.102 k8s-102
192.168.56.103 k8s-103

注意:

  1. 按需调整 IP 和 Host

crictl 设置代理

配置 crictl

crictl config runtime-endpoint unix:///run/containerd/containerd.sock

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

# 搜索 SystemdCgroup,将其值改为 true

设置代理

mkdir /etc/systemd/system/containerd.service.d

cat > /etc/systemd/system/containerd.service.d/http_proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://10.1.1.32:7890"
Environment="HTTPS_PROXY=http://10.1.1.32:7890"
Environment="NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,10.244.0.0/16"
EOF

注意:

  1. 修改代理服务器地址
  2. NO_PROXY 需要加入 serviceSubnet 和 podSubnet

重启 containerd:

systemctl daemon-reload && systemctl restart containerd && systemctl enable containerd

测试

crictl pull registry.k8s.io/pause:3.9

生成 kubeadm init 的配置文件

生成示例配置文件

kubeadm config print init-defaults >kubeadm-config.yaml

基于示例配置编写配置文件

  1. 修改 localAPIEndpoint.advertiseAddress
  2. 修改 nodeRegistration.name
  3. 添加 networking.pubSubnet

kubeadm-config.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.56.101
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: k8s-101
  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.28.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
  podSubnet: 10.244.0.0/16
scheduler: {}

从 5.1 开始继续执行


常用命令

  1. 查看 kubelet 日志
    journalctl -xeu kubelet