window虚拟机安装centos:

windows系统下安装linux(centos7)虚拟机详细教程(virtualbox环境)_windows安装linux虚拟机-CSDN博客

准备3台机器:

172.29.34.250

172.29.37.174

172.29.39.106

安装教程:

24前版本安装:

centos7安装kubernetes教程-腾讯云开发者社区-腾讯云 (tencent.com)

24后版本安装:

安装前准备更换yum源:

        备份:

        sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

        下载:

        sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

        清理与生成缓存:

        sudo yum clean all
        sudo yum makecache

2CentOS7.9+Kubernetes1.29.2+Docker25.0.3高可用集群二进制部署_docker 25.0.3 对应的k8s版本-CSDN博客

24版本后需要安装containerd:

containerd config default | sudo tee /etc/containerd/config.toml

# 修改cgroup Driver为systemd
sed -ri 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml

# 更改sandbox_image
sed -ri 's#registry.k8s.io\/pause:3.6#registry.aliyuncs.com\/google_containers\/pause:3.9#' /etc/containerd/config.toml

# 添加镜像加速
# https://github.com/DaoCloud/public-image-mirror
# 1、指定配置文件目录
sed -i 's/config_path = ""/config_path = "\/etc\/containerd\/certs.d\/"/g' /etc/containerd/config.toml
# 2、配置加速
# docker.io 镜像加速
mkdir -p /etc/containerd/certs.d/docker.io
cat > /etc/containerd/certs.d/docker.io/hosts.toml << 'EOF'
server = "https://docker.io" # 源镜像地址

[host."https://xk9ak4u9.mirror.aliyuncs.com"] # 阿里-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://docker.m.daocloud.io"] # 道客-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://dockerproxy.com"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.mirrors.sjtug.sjtu.edu.cn"] # 上海交大-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://docker.mirrors.ustc.edu.cn"] # 中科大-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://docker.nju.edu.cn"] # 南京大学-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://registry-1.docker.io"]
  capabilities = ["pull","resolve","push"]
EOF

# registry.k8s.io 镜像加速
mkdir -p /etc/containerd/certs.d/registry.k8s.io
cat > /etc/containerd/certs.d/registry.k8s.io/hosts.toml << 'EOF'
server = "https://registry.k8s.io"

[host."https://k8s.m.daocloud.io"]
  capabilities = ["pull", "resolve", "push"]
EOF

# quay.io 镜像加速
mkdir -p /etc/containerd/certs.d/quay.io
cat > /etc/containerd/certs.d/quay.io/hosts.toml << 'EOF'
server = "https://quay.io"

[host."https://quay.m.daocloud.io"]
  capabilities = ["pull", "resolve", "push"]
EOF

# docker.elastic.co镜像加速
mkdir -p /etc/containerd/certs.d/docker.elastic.co
tee /etc/containerd/certs.d/docker.elastic.co/hosts.toml << 'EOF'
server = "https://docker.elastic.co"

[host."https://elastic.m.daocloud.io"]
  capabilities = ["pull", "resolve", "push"]
EOF

systemctl daemon-reload

systemctl enable containerd --now

systemctl restart containerd
systemctl status containerd

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


cat > /root/kube/kubeadm_init/kubeadm-init.yaml << EOF
 # 针对性修改
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.137.51 # 修改自己的ip
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: k8s-1
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/k8s-1
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
#controlPlaneEndpoint: 192.168.1.10:9443 # 高可用vip的ip
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: 1.28.2
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
EOF

#解决 Kubernetes 中 Kubelet 组件报 failed to get cgroup 错误
vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
CPUAccounting=true
MemoryAccounting=true


Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice"

#所有节点配置crictl客户端连接的Runtime位置:
cat > /etc/crictl.yaml <<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
EOF


# 查看所需镜像列表
kubeadm config images list --config kubeadm-init.yaml

kubeadm config images list --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.28.2

# 预拉取镜像
kubeadm config images pull --config kubeadm-init.yaml

kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.28.2 --cri-socket unix:///var/run/containerd/containerd.sock


# 初始化
kubeadm init --config=kubeadm-init.yaml --upload-certs --dry-run

kubeadm init --config=kubeadm-init.yaml --upload-certs | tee kubeadm-init.log


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


kubeadm join 192.168.137.51:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:7c6a27fac5a24f4f33408048346d371e01429e0dc666a66552be10e2febc6a41 --cri-socket unix:///var/run/containerd/containerd.sock

问题处理:

kubeadm init初始化报错_kubeadm init报错-CSDN博客

K8S部署---故障处理 - chalon - 博客园 (cnblogs.com)

k0s错误cni plugin not initialized-张良人技术博客 (kling.cn)

k8s中metrics-server异常http: TLS handshake error from 172.30.117.64:25970: EOF - 简书 (jianshu.com)

k8s 之 containerd 安装信任根证书 - 江流入海 - 博客园 (cnblogs.com)

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐