• Ubuntu20.04安装k8s v1.21.0


    1. 禁用swap分区, 修改网络配置

    sudo vim /etc/fstab
    把有swap的那一行注释掉即可,如下:
    在这里插入图片描述
    然后执行如下命令

    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
    • 2
    • 3
    • 4
    • 5

    2. 安装docker

    sudo apt update
    sudo apt install docker.io
    sudo systemctl start docker
    sudo systemctl enable docker
    
    • 1
    • 2
    • 3
    • 4

    修改cgroups为systemd

    vim /etc/docker/daemon.json
    # 将下面的json内容添加到文件中
    {
      "exec-opts": ["native.cgroupdriver=systemd"]
    }
    systemctl daemon-reload
    systemctl restart docker
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3. 安装kubernetes

    1. 添加kubernetes的镜像源

    sudo apt-get update && sudo apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl
    curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
    sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF 
    deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
    EOF
    
    sudo apt-get update  # 这里要更新源,否则没法安装
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2. 安装相应版本的kubectl,kubelet和kubeadm

    sudo apt install kubectl=1.21.0-00 kubelet=1.21.0-00 kubeadm=1.21.0-00
    sudo apt-mark hold kubelet kubeadm kubectl
    
    • 1
    • 2

    3. 查看kubernetes安装所需要的docker镜像

    kubeadm config images list --kubernetes-version=v1.21.0
    
    • 1

    结果如下:

    k8s.gcr.io/kube-apiserver:v1.21.0
    k8s.gcr.io/kube-controller-manager:v1.21.0
    k8s.gcr.io/kube-scheduler:v1.21.0
    k8s.gcr.io/kube-proxy:v1.21.0
    k8s.gcr.io/pause:3.4.1
    k8s.gcr.io/etcd:3.4.13-0
    k8s.gcr.io/coredns/coredns:v1.8.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    4. 由于外网的原因,从阿里云下载镜像

    这里下载的各个镜像后边的版本,是跟上边的版本一一对应的,这个需要注意,自己找好对应的版本

    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.21.0
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.21.0
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.21.0
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.21.0
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.4.1
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0
    sudo docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    下载好后改名为kubernetes需要的名字

    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.21.0 k8s.gcr.io/kube-apiserver:v1.21.0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.21.0 k8s.gcr.io/kube-controller-manager:v1.21.0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.21.0 k8s.gcr.io/kube-scheduler:v1.21.0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.21.0 k8s.gcr.io/kube-proxy:v1.21.0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.4.1 k8s.gcr.io/pause:3.4.1
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.0 k8s.gcr.io/coredns/coredns:v1.8.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5. master节点初始化

    kubeadm init \ 
    --kubernetes-version=v1.21.0 \
    --pod-network-cidr=10.244.0.0/16 \
    --service-cidr=10.96.0.0/12
    
    • 1
    • 2
    • 3
    • 4

    出现如下内容就是安装成功

    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.43.106:6443 --token rjgf90.4glae3d5cq3n72uz \
            --discovery-token-ca-cert-hash sha256:8db99c28c7f0ff57b29141d81f74bdf47a95f0441dcb4bb0a734f46fcf67e518
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    根据安装成功后的提示,我们应该执行如下代码

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

    4. 安装网络插件calico

    在初始化的时候我们配置了--pod-network-cidr=10.244.0.0/16 就是给calico用的,安装calico执行如下命令:

    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/tigera-operator.yaml
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/custom-resources.yaml
    
    • 1
    • 2

    命令格式是kubecel create -f xxxxxx.yaml 后边就是yaml文件的名字,如果网络执行失败,可以直接手动访问这两个网站,把内容先下载到本地,然后执行kubectl create -f tigera-operator.yaml 即可
    安装完毕后,执行kubectl get pods -n calico-system查看pods如下:
    在这里插入图片描述
    看到ready这里都准备好后即安装成功

  • 相关阅读:
    如何解决Ubuntu系统域名解析失败的问题
    Python爬取的网页,需要解码怎么办
    Vue开发历程---音乐播放器的继续
    Spring实战之Bean的主要装配机制之一-通过Java代码显示装配bean
    「AI反诈与智能风控」闭门研讨会报名丨青源Workshop第26期
    亥姆霍兹线圈主要用途有哪些
    如何通过WinDbg获取方法参数值
    MMDetection counts detected objects
    超级炫酷的终端神器 eDEX-UI
    【AI】生成模型变得简单:了解它们的工作原理和不同类型
  • 原文地址:https://blog.csdn.net/weixin_44415928/article/details/127804242