美文网首页
使用kubeadm部署基于containerd的kubernet

使用kubeadm部署基于containerd的kubernet

作者: memoryoverrun | 来源:发表于2021-11-22 16:17 被阅读0次

本配置基于centos7

系统配置

  • 加载内核模块
sudo modprobe overlay
sudo modprobe br_netfilter

cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
  • 配置系统参数
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

执行命令让配置生效

sudo sysctl -p /etc/sysctl.conf

安装配置containerd

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum --enablerepo=docker-ce-stable-x86_64 install containerd.io
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# Setup required sysctl params, these persist across reboots.
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system            
containerd config default | sudo tee /etc/containerd/config.toml

替换成国内镜像源
endpoint = ["https://registry-1.docker.io"] 改成 endpoint = ["https://registry.aliyuncs.com"]
启动服务

sudo systemctl enable containerd
sudo systemctl restart containerd

安装kubernetes

  1. 下载k8s工具
cat <<EOF |sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]                           
name=Kubernetes                        
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
sudo yum install -y kubelet kubeadm kubectl
  1. 修改kubeadm配置
kubeadm config print init-defaults > kubeadm-config.yaml
  • cgroupDriver
    在kubeadm-config.yaml文件里增加以下内容
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
  • 镜像源
    修改前配置(默认)
imageRepository: k8s.gcr.io

修改后配置

imageRepository: registry.aliyuncs.com/google_containers
  1. 配置crictl
crictl config runtime-endpoint /run/containerd/containerd.sock

部署集群

master节点

kubeadm init --config=kubeadm.yaml

集群时区

以flanneld为例
先创建ds-patch.yaml文件

apiVersion: v1
metadata:
  name: kube-flannel-ds
spec:
  template:
    spec:
      containers:
      - name: kube-flannel
        volumeMounts:
        - name: timezone
          mountPath: /etc/localtime
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai

然后打补丁

kubectl patch --namespace=kube-system ds/kube-flannel-ds --patch "$(cat ds-patch.yaml)"

相关文章

网友评论

      本文标题:使用kubeadm部署基于containerd的kubernet

      本文链接:https://www.haomeiwen.com/subject/ifpozltx.html