Kubernetes, or K8s for short, is an abbreviation of “ubernete” with 8 characters instead of 8. Kubernetes is an open source, used to manage containerized applications on multiple hosts in the cloud platform. The goal of Kubernetes is to make the deployment of containerized applications simple and powerful. Kubernetes provides a mechanism for application deployment, planning, updating and maintenance. [1] The traditional way to deploy applications is through plug-ins or scripts. The disadvantages of this method are that the operation, configuration, management, and life cycle of applications are bound to the current operating system, which is not conducive to the upgrade, update, or rollback of applications. Of course, you can also create VMS to implement certain functions, but VMS are very heavy, which is not conducive to portability. The new approach is implemented through the deployment of containers, each container isolated from each other, each container has its own file system, processes between containers do not affect each other, can distinguish computing resources. Compared to virtual machines, containers can be deployed quickly. Because containers are decoupled from the underlying infrastructure and machine file systems, they can be migrated between different clouds and operating systems of different versions. Each application can be packaged into a container image. The one-to-one relationship between each application and the container also gives the container greater advantages. Container images can be created for the application at the build or release stage, because each application does not need to be combined with the rest of the application stack. It is also independent of the production environment infrastructure, which provides a consistent environment from development to testing and production. Similarly, containers are lighter and more “transparent” than virtual machines, which makes them easier to monitor and manage.
1. Disable swap
1.1. Temporary disable
swapoff -a
Copy the code
1.2. Permanently disable swap
Comment a swap line
vim /etc/fstab
Copy the code
2. Disable the firewall
systemctl stop firewalld
systemctl disable firewalld
Copy the code
3. Close Selinux
sed -i 's/enforcing/disable/' /etc/selinux/config
setenforce 0
Copy the code
4. Add host name and IP address mapping (for all nodes)
Vim /etc/hosts 192.0.0.171 K8S-master 192.0.0.141 k8S-node1Copy the code
5. Pass the bridged IPv4 traffic to the iptables chain
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
Copy the code
sysctl --system
Copy the code
6, all nodes installation Docker/kubeadm/kubelet/kubectl
K8s default CRI (container runtime) is Docker
6.1 Docker Installation
yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker - ce - 18.09.9 docker - ce - cli - 18.09.9 containerd.io -y systemctl start docker systemctlenable docker
docker --version Specifies version 18.09.9
Copy the code
6.2. Add aliyun kubernetesYUM software source
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=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
Copy the code
6.3, install,
Yum install -y kubelet-1.16.4 kubeadm-1.16.4 kubectl-1.16.4 systemctlenable kubelet && systemctl start kubelet
Copy the code
7. Deploy k8S Master
Reset master (if you need it, if it has been deployed before)
kubeadm reset
rm -rf $HOME/.kube/config
Copy the code
7.2. Deploy the Master
Kubeadm init --kubernetes-version=1.16.4 \ --apiserver-advertise-address=192.0.0.171 \ --image-repository Registry.aliyuncs.com/google_containers \ - service - cidr = 10.1.0.0/16 \ - pod - network - cidr = 10.244.0.0/16Copy the code
7.2.1 Record the last part of the generated content
Kubeadm join 192.0.0.171:6443 --token qkgwxh.2dkyy2b699a00rdy \ --discovery-token-ca-cert-hash sha256:e73abc5afc2f0c532b65a9e1c5cf80d69f6e6553d4660a6a457ff502b7d9d8c8Copy the code
7.2.2 Creating kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Copy the code
7.2.3 Kubectl can be automatically supplemented
source <(kubectl completion bash)
Copy the code
7.2.4 Installing the Flannel plug-in
Node Each node needs to pull the Flannel mirror
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
Copy the code
7.2.5 Viewing pods
kubectl get pods -n kube-system
Copy the code
8. Deploy the K8S node
Kubeadm join 192.0.0.171:6443 --token qkgwxh.2dkyy2b699a00rdy \ --discovery-token-ca-cert-hash sha256:e73abc5afc2f0c532b65a9e1c5cf80d69f6e6553d4660a6a457ff502b7d9d8c8Copy the code
Run ‘kubectl get nodes’ on the control-plane to see this node join the cluster. If the node is added successfully, view the Master node
kubectl get nodes
Copy the code
9. Test the cluster
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc
Copy the code
Wait for the container to start, use nodeIP+port to access
10. Install Kubernetes-Dashboard
10.1. Download Ymal
Wget HTTP: / / https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-bate8/aio/deploy/recommended.yamlCopy the code
10.2. Configure YAML
sed -i 's/kubernetesui/registry.cn-hangzhou.aliyuncs.com\/loong576/g' recommended.yaml
Copy the code
10.3. Configure NodePort
sed -i '/targetPort: 8443/a\ \ \ \ \ \ nodePort: 30002\n\ \ type: NodePort' recommended.yaml
Copy the code
10.4. Deploying dashboard
kubectl apply -f recommended.yaml
kubectl get pods -n kubernetes-dashboard
kubectl get pods,svc -n kubernetes-dashboard
Copy the code
10.5 Log in to Dashboard
To access the address, note that it’s HTTPS, use firefox
https://<nodeIP><nodePort>
Copy the code
10.6. Create an Administrator
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
Copy the code
10.7. Obtain the Token
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | grep dashboard-admin | awk '{print $1}')
Copy the code