安装docker
参考docker官方文档安装
-
设置存储库
$ sudo apt-get update $ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg $ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
-
安装 Docker 引擎
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
-
验证 Docker 是否安装成功
$ sudo docker run hello-world
k8s相关资源/工具安装
参考kubernetes官方文档安装,但需要注意的是部分镜像因为网络原因无法拉取到,所以需要替换这部分镜像
-
安装 kubeadm、kubelet、kubectl
$ sudo apt-get update $ sudo apt-get install -y apt-transport-https ca-certificates curl $ 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 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 $ sudo apt-get install -y kubelet kubeadm kubectl $ sudo apt-mark hold kubelet kubeadm kubectl
-
配置 cgroup 驱动程序
$ sudo vim /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"] } $ sudo systemctl daemon-reload $ sudo systemctl restart docker
-
使用 kubeadm 创建集群
$ sudo kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
成功后显示如下:
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 ip:port --token xxx \ --discovery-token-ca-cert-hash sha256:xxx
-
复制 kubeconfig 并验证 k8s 集群
$ sudo cp -i /etc/kubernetes/admin.conf kubeconfig $ sudo chmod 777 kubeconfig $ export KUBECONFIG=kubeconfig $ kubectl get ns
-
安装网络插件 flannel
项目地址:https://github.com/flannel-io/flannel
yaml地址:https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
$ kubeclt apply -f kube-flannel.yaml
-
控制平面节点隔离
$ kubectl taint node <node_name> --all node-role.kubernetes.io/master-