Kubernetes1.15.2 cluster deployment and deployment Metrics Server plug-in

Environmental Information:

operating system CPU name IP addresses
CentOS 7.6 k8s-master 192.168.31.61
CentOS 7.6 k8s-node1 192.168.31.62
CentOS 7.6 k8s-node2 192.168.31.63

1. Installation Requirements

Before you begin, deploy Kubernetes cluster machines need to meet the following conditions:

  • Operating System CentOS7.x-86_x64
  • Hardware configuration: 2GB or more RAM, 2 or more of CPU CPU, hard disk 30GB or more
  • Cluster network interworking between all machines
  • You can access the Internet, necessary to pull the mirror
  • Prohibit swap partition

2. Learning Objectives

  1. Docker installed on all nodes and kubeadm
  2. Department Kubernetes Master
  3. Plug container network deployment
  4. Deployment Kubernetes Node, the node joins the cluster Kubernetes
  5. Deploy Dashboard Web pages, visual view Kubernetes resources

3. Prepare the environment

关闭防火墙:
$ systemctl stop firewalld
$ systemctl disable firewalld

关闭selinux:
$ sed -i 's/enforcing/disabled/' /etc/selinux/config 
$ setenforce 0

关闭swap:
$ swapoff -a    临时
$ sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab  永久

添加主机名与IP对应关系(记得设置主机名):
$ cat /etc/hosts
192.168.31.61 k8s-master
192.168.31.62 k8s-node1
192.168.31.63 k8s-node2

将桥接的IPv4流量传递到iptables的链:
$ cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1

EOF
$ sysctl --system

4. All nodes installed Docker / kubeadm / kubelet

4.1 Installation Docker

$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce
$ systemctl enable docker && systemctl start docker

4.2 Add Ali cloud YUM repositories

$ cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

4.3 installation kubeadm, kubelet and kubectl

Specifies the version number of the deployment:

$ yum install -y kubelet-1.15.2 kubeadm-1.15.2 kubectl-1.15.2
$ systemctl enable kubelet

5. department Kubernetes Master

(Master) performed at 192.168.31.63.

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

Since the default image address k8s.gcr.io pull the country inaccessible, specify the address of the warehouse Ali cloud mirrored here.

Use kubectl tools:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl get nodes

6. Install Network Pod plug (the CNI)

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

Ensure access to quay.io this registery.

If the download fails, you can change this image Address: lizhenliang / flannel: v0.11.0-amd64

7. subscription Kubernetes Node

In 192.168.31.62/63(Node) execution.

Add new nodes to the cluster, perform kubeadm join in kubeadm init command output:

$ kubeadm join 192.168.31.61:6443 --token esce21.q6hetwm8si29qxwn \
    --discovery-token-ca-cert-hash sha256:00603a05805807501d7181c3d60b478788408cfe6cedefedb1f97569708be9c5

8. Test kubernetes cluster

Creating a pod in Kubernetes cluster, verify proper operation:

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

9. deploy Dashboard

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

Domestic default image can not be accessed, modified, mirroring address: lizhenliang / kubernetes-dashboard-amd64: v1.10.1

The default Dashboard only within the cluster to access, modify Service is NodePort type, exposed to the outside:

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard
$ kubectl apply -f kubernetes-dashboard.yaml

Access Address: HTTP: // NodeIP: 30001

Create a service account and bind default cluster-admin administrator roles in a cluster:

$ kubectl create serviceaccount dashboard-admin -n kube-system
$ kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
$ kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')

Using the output of token login Dashboard.

Kubernetes cluster installation Metrics Server

$ git clone https://github.com/kubernetes-incubator/metrics-server
下载完成后还需要对 metrics-server/deploy/1.8+/resource-reader.yaml文件进行修改
##官方仓库中的清单文件metrics-server-deployment.yaml中未明确主程序metrics-server传递参数指定指标数据的获取接口,它通常应该是kubernetes.summary_api

     image: registry.aliyuncs.com/google_containers/metrics-server-amd64:v0.3.3
      args:
      - --kubelet-insecure-tls
      - --kubelet-preferred-address-types=InternalIP

After modifying can be used directly

$ kubectl apply -f deploy/metrics-server/deploy/1.8+/

View pod whether the Running state

$   
kubectl get pod -n kube-system

View node, POD resource monitoring

kubectl top node
kubectl top pods -n kube-system

Kubernetes1.15.2 cluster deployment and deployment Metrics Server plug-in
Kubernetes1.15.2 cluster deployment and deployment Metrics Server plug-in
Kubernetes1.15.2 cluster deployment and deployment Metrics Server plug-in

Reference Lizhen Liang teacher's blog: https://blog.51cto.com/lizhenliang/2296100

Guess you like

Origin blog.51cto.com/shunzi115/2439081