A, preparation,

1. Cluster servers

Three or more servers are recommended to form a cluster. CentOS8.0 is used as an example.

The IP address note
192.168.1.1 master
192.168.1.2 instead node1
192.168.1.3 node2
Check whether the system kernel version is 8.0
cat /etc/centos-release
# check the IP address as above
ifconfig
Copy the code

2. Update the source

# Delete the original warehouse and add aliyun warehouse
rm -rfv /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
Update to install common dependencies
yum update
yum install vim bash-completion net-tools gcc -y
Copy the code

3. Change the host name

# change the host name to master, node1, node2
vim /etc/hostname
Add hosts to master and Node respectivelyVim /etc/hosts 192.168.1.1 master 192.168.1.2 node1 192.168.1.3 node2Copy the code

4. Close the swap

Close # swap
swapoff -a
# comment swap
vim /etc/fstab
Copy the code

5. Configure the kernel

Pass the bridge IPv4 traffic to the chain of iptables
cat>/etc/sysctl.d/k8s.conf<<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF 
sysctl --system
Copy the code

Install Docker

1. Aliyuan installation

yum install -y yum-utils device-mapper-persistent-data lvm2 
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
Copy the code

2. Modify the image source

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
 "registry-mirrors":  ["https://otv9pb9m.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
Copy the code

If Docker fails to start, reboot the server.

Install Kubernetes

1. Add the K8S warehouse

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

2. Install k8s

yum install -y kubectl kubelet kubeadm
Set boot up
systemctl enable kubelet
# Check the K8S version
kubectl version
#version Enter the version number
#apiserver Fill in the master addressKubeadm init --kubernetes-version=1.20.4 \ --apiserver-advertise-address=192.168.1.1 \ --image-repository Registry.aliyuncs.com/google_containers \ - service - cidr = 10.10.0.0/16 - pod - network - cidr = 10.122.0.0/16Copy the code

Note the following information after the installation. The child nodes need to be linked to the master node via kubeadm Join.

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.1.1:6443 -- Token yis2v6. u5D1XU6v1v0xfNbn \ -- Discovery-token-ca-cert-hash sha256:9b4b468a10c257867c14e41e3e9c4c6bacaff477a61d294e6e18b6e39cdec809Copy the code
# to create kubectl
mkdir -p $HOME/.kube
sudo  cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo  chown  $(id -u):$(id -g)  $HOME/.kube/config
Make Kubectl automatically replenished
source  <(kubectl completion bash)
Copy the code

3. Configure the network

View nodes and namespaces within the cluster
kubectl get node
kubectl get pod --all-namespaces
Copy the code

At this point, node is NotReady because CoredNspod is not started and netPod is missing

Kubectl apply -f HTTPS://docs.projectcalico.org/manifests/calico.yaml
Copy the code

After the network environment is installed, the node is ready.

4. The dashboard

# pull resourcesWget HTTP: / / https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc7/aio/deploy/recommended.yamlCopy the code

vim recommended.yaml

kind: Service
apiVersion: v1
metadata:
 labels:
 k8s-app: kubernetes-dashboard
 name: kubernetes-dashboard
 namespace: kubernetes-dashboard
spec:
 type: NodePort
 ports:
 - port: 443
 targetPort: 8443
 nodePort: 30000
 selector:
 k8s-app: kubernetes-dashboard
Copy the code

After downloading the YAMl file locally, add type and nodeport to the service

Install the dashboard
kubectl create -f recommended.yaml
Copy the code
Create a dashboard admin user
kubectl create serviceaccount dashboard-admin -n kube-system
# bind the created Dashboard user to an administrative user
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
Get the token name for the newly created user
kubectl get secrets -n kube-system |  grep dashboard
Output: dashboard-admin-token-88gxw
# Refer to the output above
kubectl describe secrets -n kube-system dashboard-admin-token-88gxw
# output token
Copy the code

Port 30000 is configured. Log in to the port using https://IP:30000 and select the token

#tokeneyJhbGciOiJSUzI1NiIsImtpZCI6Ik1YU183MUtramZLYWw4d1dzRm9pTlU3akMwRmlOQlFxaE1GWmppam12b1UifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3Nlc nZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZ WFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tajI4bGQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtY WNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiMWYwODhhO DctNjA2Ny00MTM2LWE5YmQtODA2MTkxYWY5N2M1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9. J9Zn5hrzCg119D4o-o3BNVFGpkiq3TtYQG05ScoNHMCuihiOAOEfb8ADs6OzOvmRBkc0zgA3YpaBoWuiW1VTV5Lh5Vix3MvhpM4kLc0fCS0QUcPvLUtZcPEf 6GrYnO06tfilWD5V-zm90v7cNhZoasw6T1G-SmbFRo-GpKad3Par_MejQuOmd4VlqGexfb58OXWEB9GTjq7_FPL4hut6E5LzN_CmouI3dkw97dmbZo8ZTV7k 0uUoiodwUJ9mzdOEaHG4G3yZt7_6FSkbUP8_rBncPe5OlN7dd6AKeC_RJCkj-I1_dd70RXKjz3iw15M-jbNcUJWySEArQjJWo6tXNgCopy the code

5. Add a node

The master machine/etc/kubernetes/admin. Conf file to the node1 and 2

mkdir -p $HOME/.kube
sudo  cp -i $HOME/admin.conf $HOME/.kube/config
sudo  chown  $(id -u):$(id -g)  $HOME/.kube/config
Copy the code

Enter the kubeadm join command above to complete the link

www.kubernetes.org.cn/7189.html