kubeadm installation Kubernetes best practices

Foreword

Kubernetes as a container layout tools to simplify container management, improve work efficiency popular. Because many novice deployment Kubernetes "×××" difficult problem, we do not have actual combat experience Comments kubeadm "×××" the easiest way to deploy the Kubernetes.

A, Kubernetes Profile

Kubernetes (referred K8S) is an open source cluster management system container, the container can be achieved automated cluster deployment, automatic scaling capacity, maintenance and other functions. It is a container layout tool, but also a new distributed architecture based program leading container technology. On the basis of Docker technology, providing a container for the application of the deployment operation, resource scheduling, service discovery and dynamic stretching and other functions, improve the convenience of large-scale container cluster management.
K8S management node in the cluster is working with two types of nodes. Management is responsible for K8S node cluster management, cluster information exchange, task scheduling between nodes, it is also responsible for managing container, Pod, NameSpaces, PV and other life cycle. Pod working node container and provide computing resources mainly, Pod and containers all run on worker nodes, the nodes to work through kubelet service node to communicate with management in order to manage the life cycle of the container, and to communicate with other nodes in the cluster.
kubeadm installation Kubernetes best practices

Second, prepare the environment

Kubernetes support running physical server or a virtual machine, virtual machine is ready to use this test environment, the hardware configuration information as shown below:

IP addresses Node Role CPU Memory Hostname Disk
10.10.10.10 master >=2c >=2G master sda
10.10.10.11 worker >=2c >=2G node1 sda
10.10.10.12 worker >=2c >=2G node2 sda

Note: the following steps on all nodes

1. Set the hostname hostname, host name setting management node master.

hostnamectl set-hostname master

When you need to set a different host name, master can be replaced with the correct hostname node1, node2 can be.
2. Edit / etc / hosts file, add the domain name resolution.

cat <<EOF >>/etc/hosts
10.10.10.10 master
10.10.10.11 node1
10.10.10.12 node2
EOF

3. Turn off the firewall, selinux and swap.

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab

4. kernel configuration parameters, IPv4 traffic will be passed to the bridging chain 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

5. Configure yum domestic source

yum install -y wget
mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
yum clean all && yum makecache

Configuring domestic Kubernetes 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

Configuration docker source

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

Third, the software installation

Note: the following steps on all nodes

1. Install docker

yum install -y docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
docker –version
Docker version 18.06.1-ce, build e68fc7a

docker services provide computing resources to run container is the basic platform for all container operations.
2. Install kubeadm, kubelet, kubectl

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet

Kubelet responsible for communication with other nodes in the cluster, and this node Pod and container life cycle management. Kubeadm Kubernetes automated deployment tools, reduces deployment easier and increase efficiency. Kubectl is Kubernetes cluster management tools.

Fourth, the master node deployment

Note: the following operations on the master node

1. Kubernetes cluster initialization master.

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

The segment is defined POD: 10.244.0.0/16, api server address is the master local IP address.
This step is critical, because the kubeadm default from the official website k8s.grc.io download the required image, domestic inaccessible, and therefore need to specify the address of the warehouse by Ali cloud images --image-repository, many novices initial deployments card can not be in this part subsequent configuration.
Cluster initialization successful return the following information:
kubeadm installation Kubernetes best practices

The last part of records generated, this content needs to be performed at other nodes join the cluster Kubernetes.

kubeadm join 10.10.10.10:6443 --token kekvgu.nw1n76h84f4camj6 \
    --discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e

2. Configure kubectl tool

mkdir -p /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get nodes
kubectl get cs

3. Deploy flannel network

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

Fifth, the deployment node node

Note: the following operations on all the nodes node

Run the following command so that all node cluster node joins Kubernetes

kubeadm join 10.10.10.10:6443 --token kekvgu.nw1n76h84f4camj6 \
    --discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e

This command returns the contents of the result when the cluster is initialized (kubeadm init).

Sixth, the cluster state detection

Note: the following operations on the master node

1. The master node of the cluster command to check the state of the input, returns this result, the cluster is normal.

kubectl get nodes
NAME     STATUS   ROLES    AGE     VERSION
master     Ready      master    26m       v1.14.2
node1      Ready      <none>   3m10s   v1.14.2
node2      Ready      <none>   3m         v1.14.2

When focus your content is STATUS Ready, then the cluster status to normal.
2. Create Pod to verify that the cluster is normal.

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc

Seven, deploy Dashboard

Note: the following operations on the master node

1. Create a file yaml the Dashboard

wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
sed -i 's/k8s.gcr.io/loveone/g' kubernetes-dashboard.yaml
sed -i "160a \ \ \ \ \ \ nodePort: 30001" kubernetes-dashboard.yaml
sed -i "161a \ \ type:\ NodePort" kubernetes-dashboard.yaml

2. Deploy Dashboard

kubectl create -f kubernetes-dashboard.yaml

3. Once created, check the operating status related services

kubectl get deployment kubernetes-dashboard -n kube-system
kubectl get pods -n kube-system -o wide
kubectl get services -n kube-system
netstat -ntlp|grep 30001

4. Enter the access address in the Dashboard Firefox browser: https://10.10.10.10:30001
5. The view access authentication token Dashboard

kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
 [root@master ~]# kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
Name:         dashboard-admin-token-kqz88
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: dashboard-admin
              kubernetes.io/service-account.uid: d4e5079b-7fcd-11e9-a14d-000c29c103df

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4ta3F6ODgiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZDRlNTA3OWItN2ZjZC0xMWU5LWExNGQtMDAwYzI5YzEwM2RmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.C-o5m6PxZqAMiDtshr6ND1sP0xcDKtPPT2paLbC0QiIXuAMO7SyLnbQAHon7WcsV-Gc5g850yNuXEiEuUJGei8nGcOO9ERRFd-AzQ79UXlYEcSNHQNx7vOy6jn05QbFJuQqO29rab4qox643TDuCRmrnMPkktFuDLFwAsFp1l1F49WCi0sgbGr_tfvdwU1pMm9Ures91PBExQFnjzW9ROp1rcHacHZiVsiu9KYE2VvTHP_yzYAdN3guHAvaSjkhP1CYuH2BBMBhJ44Hcg20ldWFiX1RN-6UalnMeApL14mIutusTbm4sWS_rxyxT0TMAobNl-Gd_wrHyctRoDF_zwA

Token 6. Login using the output of the Dashboard.
kubeadm installation Kubernetes best practices
After authentication, the login Home Dashboard Figure
kubeadm installation Kubernetes best practices

We welcome the public interest is scanned number will regularly share IT technical articles, are subject to other technical problems, they can always consult.

kubeadm installation Kubernetes best practices

Guess you like

Origin blog.51cto.com/9099998/2405064