k8s install


Kebeadm 安装

export KUBECONFIG=/etc/kubernetes/admin.conf

kubeadm join 172.16.21.75:6443 --token c19ozz.fes3zyf06ugr4sj4 \
    --discovery-token-ca-cert-hash sha256:6e712a7fd41a09d3480bfd443221a4e23969367e37dba44944f0aad200e84a13
  1. 基础环境设置

    sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
             -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
             -i.bak \
             /etc/yum.repos.d/CentOS-Linux-AppStream.repo \
             /etc/yum.repos.d/CentOS-Linux-BaseOS.repo \
             /etc/yum.repos.d/CentOS-Linux-Extras.repo \
             /etc/yum.repos.d/CentOS-Linux-PowerTools.repo \
             /etc/yum.repos.d/CentOS-Linux-Plus.repo
    
     dnf clean all && dnf makecache
    
    

172.16.21.75 master
172.16.21.76 low
172.16.21.77 high

swapoff

swapoff -a

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe – ip_vs
modprobe – ip_vs_rr
modprobe – ip_vs_wrr
modprobe – ip_vs_sh
modprobe – nf_conntrack_ipv4
EOF

chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

dnf -y install ipset ipvsadm






1. 设置 `br_netfilter`

   ```shell
   cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
   br_netfilter
   EOF

   cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
   net.bridge.bridge-nf-call-ip6tables = 1
   net.bridge.bridge-nf-call-iptables = 1
   EOF
   sudo sysctl --system
  1. 安装 docker

    dnf config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && dnf install -y https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/docker-ce-20.10.5-3.el8.x86_64.rpm

  2. 设置 docker cgroup and storage

    sudo mkdir /etc/docker
    cat <<EOF | sudo tee /etc/docker/daemon.json
    {
      "exec-opts": ["native.cgroupdriver=systemd"],
      "log-driver": "json-file",
      "log-opts": {
        "max-size": "100m"
      },
      "storage-driver": "overlay2",
      "registry-mirrors": ["https://kkw5ad1d.mirror.aliyuncs.com"]
    }
    EOF
    
    

重启

systemctl enable docker
systemctl daemon-reload
systemctl restart docker




4. 配置中科大源

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/

baseurl=http://mirrors.ustc.edu.cn/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF

将 SELinux 设置为 permissive 模式(相当于将其禁用)

setenforce 0
sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/‘ /etc/selinux/config

dnf install -y kubelet kubeadm kubectl –disableexcludes=kubernetes

systemctl enable –now kubelet




5. 拉取镜像

   ```bash
   export ALI=registry.cn-hangzhou.aliyuncs.com/google_containers/
   export K8S=k8s.gcr.io/
   export VER=v1.20.5
   export ETCDVER=3.4.13-0
   export PAUSEVER=3.2
   export DNSVER=1.7.0

   apiserver=kube-apiserver:$VER;docker pull $ALI$apiserver && docker tag $ALI$apiserver $K8S$apiserver

   controller=kube-controller-manager:$VER;docker pull $ALI$controller && docker tag $ALI$controller $K8S$controller

   schedule=kube-scheduler:$VER;docker pull $ALI$schedule && docker tag $ALI$schedule $K8S$schedule

   proxy=kube-proxy:$VER;docker pull $ALI$proxy && docker tag $ALI$proxy $K8S$proxy

   etcd=etcd:$ETCDVER;docker pull $ALI$etcd && docker tag $ALI$etcd $K8S$etcd

   pause=pause:$PAUSEVER;docker pull $ALI$pause && docker tag $ALI$pause $K8S$pause

   coredns=coredns:$DNSVER;docker pull $ALI$coredns && docker tag $ALI$coredns $K8S$coredns

FAQ

  1. failed to acquire lease: cidr not assigned

kubeadm init 时,未指定 cidr ==> --pod-network-cidr=10.244.0.0/16


文章作者: peifeng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 peifeng !
  目录