Pre deployment preparation
- A Tencent cloud lightweight application server (CPU: 2 cores | memory: 4GB | hard disk: 80GB), master
- A Tencent cloud server (CPU: 1 core | memory: 2GB | hard disk: 50GB), node1
- The operating system is Ubuntu 20.04 lts x86_ sixty-four
- There is a big hole here. The intranet of lightweight application server and ordinary cloud server is not interconnected. The interconnection should be referred to NAT Traversal
- reference resources gist And combined with their own reality
master
Switch to root
sudo su root
Install docker
curl -fsSL https://get.docker.com | sudo sh -s -- --mirror Aliyun sudo usermod -aG docker $USER sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "registry-mirrors": ["https://t9ab0rkd.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
Installation k8s Kit
# Add and trust APT certificates curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - # Add source address add-apt-repository "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" # Update the source and install the latest version of kubenetes sudo apt update && apt install -y kubelet kubeadm kubectl # Add completion, preferably in. bashrc source <(kubectl completion bash) source <(kubeadm completion bash)
Close swap (I didn't do it)
Use kubedm to initialize the cluster and start the master node
kubeadm init --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
Configure admin.conf
The connection to the server localhost: 8080 was rejected
If root
# append to .bashrc export KUBECONFIG=/etc/kubernetes/admin.conf
If it is an ordinary user
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install network plug-in
There are many network solutions, such as flannel. Choose weave here
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
I've been waiting here for a long time. The status of weave pods is Running
node1
Switch to root
sudo su root
Install docker
curl -fsSL https://get.docker.com | sudo sh -s -- --mirror Aliyun sudo usermod -aG docker $USER sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "registry-mirrors": ["https://t9ab0rkd.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
Installation k8s Kit
# Add and trust APT certificates curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - # Add source address add-apt-repository "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" # Update the source and install the latest version of kubenetes sudo apt update && apt install -y kubelet kubeadm kubectl # Add completion, preferably in. bashrc source <(kubectl completion bash) source <(kubeadm completion bash)
Join k8s cluster
Go back to the master node and get the complete kubedm join command
kubeadm token create --print-join-command
Output results:
kubeadm join 10.0.xx.xx:6443 --token 67k0f6.3honxkg120rmxd3d --discovery-token-ca-cert-hash sha256:56a4f123422e7f3a863914503acd344377a6e0f77dd8f979d66b44b257b1fc5
Note that the address after kubedm join cannot be changed to the public address. There is a hole here. The master is Tencent cloud lightweight application server, and node1 is Tencent ordinary cloud server. I refer to it NAT Traversal After that, the Intranet can be ping ed.
Go back to node1 node and use kubedm join
kubeadm join 10.0.xx.xx:6443 --token 67k0f6.3honxkg120rmxd3d --discovery-token-ca-cert-hash sha256:56a4f123422e7f3a863914503acd344377a6e0f77dd8f979d66b44b257b1fc5
Configure admin.conf
The connection to the server localhost: 8080 was rejected
Use scp to copy / etc/kubernetes/admin.conf of master to / etc/kubernetes/admin.conf of node1
scp /etc/kubernetes/admin.conf user@ip:/etc/kubernetes/
If root
# append to .bashrc export KUBECONFIG=/etc/kubernetes/admin.conf
If it is an ordinary user
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install network plug-in
There are many network solutions, such as flannel. Choose weave here
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
I've been waiting here for a long time. The status of weave pods is Running
View nodes
In master or node1
kubectl get nodes
Here, the ROLES of node1 may be None, which can be solved by using the following command
kubectl label node {node_name} node-role.kubernetes.io/worker=worker
Effect screenshot
summary
- thank This gist , practice the truth.
- I have used minicube and played stand-alone k8s clusters before, but I think the cloud is native. Only by playing on the cloud and simulating the actual production environment can I really learn something.