K8S环境搭建

Linux 安装

本教程采用:

 - VMware Fusion(Professional Version 11.5.0)

- Linux CentOS Linux release 7.7.1908 (Core), 可以采用命令查看: cat /etc/centos-release

Linux设置:

关闭防火墙

        sudo systemctl stop firewalld
        sudo systemctl disable firewalld

关闭Swap

    临时关闭: swapoff -a

    确认状态: free -m

    永久关闭: vi /etc/fstab
             注释这行: #/dev/mapper/centos-swap swap swap defaults 0 0

设置网络

更改3台机器的主机名, 注意:主机名不能带下划线,只能带中划线, 否则报错

    hostnamectl set-hostname local.master
    hostnamectl set-hostname local.node3
    hostnamectl set-hostname local.node2

设置主机: vi /etc/hosts

        192.168.9.136  local.master
        192.168.9.145  local.node1
        192.168.9.146  local.node2

设置DNS: vi /etc/resolv.conf

     nameserver 8.8.8.8
     nameserver 8.8.4.4

确保网络正确,并且可以相互Ping通

        ping -c 4 baidu.com 
        ping -c 4 local.node1

设置固定IP,并关闭GUI
        #systemctl set-default graphical.target
        systemctl set-default multi-user.target
        systemctl get-default

安装Docker

        可以参考: https://docs.docker.com/engine/install/centos/

        sudo yum install-yyum-utils
        sudo yum install docker-ce docker-ce-cli containerd.io

   设置加速镜像

        ## sudo systemctl start docker
        ## mirror
        sudo mkdir -p /etc/docker   
        sudo tee /etc/docker/daemon.json <<-'EOF'
        {
            "registry-mirrors": ["https://2tg9cafm.mirror.aliyuncs.com"]
        }
        EOF

        sudo systemctl daemon-reload
        sudo systemctl restart docker

安装Kubernate组件

在每台机器上面分别跑下列命令

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetesbaseurl=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

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

安装Kubernates

       echo vm.swappiness=0 > /etc/sysctl.d/k8s.conf
        vi /etc/sysctl.d/k8s.conf
        粘贴内容: vm.swappiness=0
        sysctl -p /etc/sysctl.d/k8s.conf

在master上面安装命令

    kubeadm init --kubernetes-version=1.18.2 \
    --apiserver-advertise-address=192.168.9.136 \
    --image-repository registry.aliyuncs.com/google_containers \
    --service-cidr=10.1.0.0/16 \
    --pod-network-cidr=10.244.0.0/16

安装成功后打印下列语句

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 

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.9.136:6443 --token x5sh6f.jw3w2yqyqir02udh \
--discovery-token-ca-cert-hash sha256:c07a389230a83fb691fdfcf7da9657365ee5df687ca0844d60da94f673d5da95                    


上面需要安装一个网络组建,否则无法安装成功, 我们选择kube-calico.yaml 

然后在每个node上面安装kubeadm join...

然后在master节点查看状态

kubectl get nodes

错误排查

systemctl status kubelet 

你可能感兴趣的:(K8S环境搭建)