Kubernetes Series 2 Minikube cluster installation

1. Introduction

When installing k8s, there is a simple installation method. You can install yum install -y etcd kubernetes through this command, and it also comes with docker. However, the k8s version installed in this way is too low, v1.5.2, and the docker installation version is also too low, v1.13. Since the versions are relatively low, there are many restrictions on subsequent learning.

Nowadays, there are many ways to install k8s. The official documentation points out that k8s can be installed with the help of Minikube tool or kubeadm tool.

Minikube is a tool that makes it easy to run Kubernetes locally. As a learning stand-alone cluster, you can use the Minikube tool to implement environment installation. Minikube runs a single-node Kubernetes cluster inside a virtual machine (VM) on a laptop for users who are experimenting with Kubernetes or developing on a daily basis. Using Minikube make sure kubectl is installed first.

Summary: Minikube is a CLI tool that can configure and manage single-node Kubernetes clusters. For learning, if it is a production environment, use the kubeadm tool to manage multi-node Kubernetes clusters.

Kubectl is a k8s client tool. The kubectl version used must be within a small version difference of the k8s cluster. For example: v1.2 client is used with v1.1, v1.2, v1.3 master server. Using the latest version of kubectl helps avoid unexpected problems.

The minimum configuration must be a 2-core CPU, and it is recommended to have at least a 2-core CPU and 4G memory

Docker version: v18.09

kubectl version: v1.17.3

Minikube version: v1.7.3 (default download and installation of k8s server v1.17.3)

1.1 Preparation

[root@hecs-x-large-2-linux-20200511094526 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@hecs-x-large-2-linux-20200511094526 ~]# systemctl disable firewalld
[root@hecs-x-large-2-linux-20200511094526 ~]# systemctl stop firewalld
[root@hecs-x-large-2-linux-20200511094526 ~]# hostnamectl set-hostname k8s-host

?1.2 Install docker

It is recommended to use docker v18.09 and above. Specific installation reference: docker series 2

[root@k8s-host bin]# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

 1.3 Install Kubectl client

  What is downloaded here is the V1.17.3 version. There is a problem with the installation of the v1.8 version.

List of download addresses for each version (you can view the source code after opening it to see the required version information): kubernetes-yum-repos-kubernetes-el7-x86_64-Packages installation package download_open source mirror station-Alibaba Cloud

After downloading, upload it to the cloud server opt directory for installation:

[root@k8s-host ~]# cd /opt
[root@k8s-host opt]# ls
containerd kubectl-1.17.3-0.x86_64.rpm
[root@k8s-host opt]# sudo yum localinstall kubectl-1.17.3-0.x86_64.rpm

Check the version information. At this time, only the client version is displayed. localhost:8080 was refused and could not connect to the Kubernetes cluster because the server requires the following minikube tool to install:

[root@k8s-host opt]# sudo kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14: 22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@k8s-host bin]# systemctl enable kubelet.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

1.4 Install Minikube tools

The minikube tool version number corresponds to the k8s server version number. After installation, the execution file is moved to the /usr/local/bin directory. The command is as follows:

sudo curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.7.3/minikube-linux-amd64 & amp; & amp; chmod + x minikube & amp; & amp; sudo mv minikube /usr/local/bin/

The minikube execution file directory is as follows:

[root@k8s-host opt]# cd /usr/local/bin
[root@k8s-host bin]# ls
minikube

Minikube tool to view version information

[root@k8s-host opt]# minikube version
minikube version: v1.7.3
commit: 436667c819c324e35d7e839f8116b968a2d0a3ff

Start the local kubernetes cluster (the first time you will pull the image from https://k8s.gcr.io)

[root@k8s-host bin]# minikube start --vm-driver=none

The domestic network pulls the image in k8s.gcr.io and the error is as follows:

error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-apiserver:v1.17.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-controller-manager:v1.17.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-scheduler:v1.17.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-proxy:v1.17.3: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/pause:3.1: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/etcd:3.4.3-0: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
    [ERROR ImagePull]: failed to pull image k8s.gcr.io/coredns:1.6.5: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1

Solution: Specify domestic mirror

[root@k8s-host bin]# minikube start --vm-driver=none --image-mirror-country=cn

You can also manually docker pull it down. You can find the pull in docker hub, or you can pull it down on Alibaba Cloud. Reference article: https://www.cnblogs.com/zhizihuakai/p/12852851.html

Check the cluster status:

[root@k8s-host bin]# minikube status
host: running
kubelet: running
apiserver: Running
kubeconfig: Configured

At this point, verify the kubectl installation and check the version information again. You have connected to the cluster environment localhost:8080, and the server version is also v1.17.3

[root@k8s-host bin]# kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14: 22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07: 13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}

Verify whether the k8s cluster is installed (added later)

[root@k8s-host ~]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-7f9c544f75-czbjr 1/1 Running 1 4d23h
kube-system coredns-7f9c544f75-hwjtb 1/1 Running 1 4d23h
kube-system etcd-k8s-host 1/1 Running 1 4d23h
kube-system kube-apiserver-k8s-host 1/1 Running 1 4d23h
kube-system kube-controller-manager-k8s-host 1/1 Running 1 4d23h
kube-system kube-proxy-ht6sb 1/1 Running 1 4d23h
kube-system kube-scheduler-k8s-host 1/1 Running 1 4d23h
kube-system storage-provisioner 1/1 Running 1 4d23h
kubernetes-dashboard dashboard-metrics-scraper-7b64584c5c-7tx44 1/1 Running 0 4d22h
kubernetes-dashboard kubernetes-dashboard-79d9cd965-gp7t7 1/1 Running 0 4d22h

Use the minikube command to shut down the k8s cluster

[root@k8s-host bin]# minikube stop
* Stopping "minikube" in none ...
* "minikube" stopped.
[root@k8s-host bin]# minikube status
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped

Start the k8s cluster again

[root@k8s-host bin]# minikube start --vm-driver=none --image-mirror-country=cn

View the running docker image file

[root@k8s-host bin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46b1d6d4594c 70f311871ae1 "/coredns -conf /etc…" About a minute ago Up About a minute k8s_coredns_coredns-7f9c544f75-hwjtb_kube-system_a178b2f8-303d-4128-bb52-35bb4d47c976_1
603dd503979a 70f311871ae1 "/coredns -conf /etc…" About a minute ago Up About a minute k8s_coredns_coredns-7f9c544f75-czbjr_kube-system_675b6dfc-4faf-49e1-b89e-3506740d495d_1
27a469c1ac53 4689081edb10 "/storage-provisioner" About a minute ago Up About a minute k8s_storage-provisioner_storage-provisioner_kube-system_209343cc-e120-4f9d-b19f-c0ef7eeb5917_1
f32ed4e06ffb ae853e93800d "/usr/local/bin/kube…" About a minute ago Up About a minute k8s_kube-proxy_kube-proxy-ht6sb_kube-system_2f4e5417-d435-4f38-b717-338ec061afe1_1
863ffa3646f8 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_coredns-7f9c544f75-hwjtb_kube-system_a178b2f8-303d-4128-bb52-35bb4d47c976_1
ee616c146c06 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_coredns-7f9c544f75-czbjr_kube-system_675b6dfc-4faf-49e1-b89e-3506740d495d_1
07ba33c30d82 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_kube-proxy-ht6sb_kube-system_2f4e5417-d435-4f38-b717-338ec061afe1_1
8592786393f8 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_storage-provisioner_kube-system_209343cc-e120-4f9d-b19f-c0ef7eeb5917_1
62a9100aa6e5 303ce5db0e90 "etcd --advertise-cl…" About a minute ago Up About a minute k8s_etcd_etcd-k8s-host_kube-system_705a0444c07b2b807f778d2099faac4c_1
cc3ee273320a d109c0821a2b "kube-scheduler --au…" About a minute ago Up About a minute k8s_kube-scheduler_kube-scheduler-k8s-host_kube-system_703c43ab97818f969f780a2cbf4d24b7_1
b4a704b4aef3 90d27391b780 "kube-apiserver --ad…" About a minute ago Up About a minute k8s_kube-apiserver_kube-apiserver-k8s-host_kube-system_38c3efc6f95b00b52427c3347f8603e6_1
74443ac19a80 b0f1517c1f4b "kube-controller-man…" About a minute ago Up About a minute k8s_kube-controller-manager_kube-controller-manager-k8s-host_kube-system_891000849224be61445397b01f007a6e_1
1bdc2c5d7472 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_etcd-k8s-host_kube-system_705a0444c07b2b807f778d2099faac4c_1
02a2d111d35f registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_kube-scheduler-k8s-host_kube-system_703c43ab97818f969f780a2cbf4d24b7_1
92fe5985bc0e registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_kube-controller-manager-k8s-host_kube-system_891000849224be61445397b01f007a6e_1
21550ecde0ce registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_kube-apiserver-k8s-host_kube-system_38c3efc6f95b00b52427c3347f8603e6_1

1.4 Install dashboard

[root@k8s-host bin]# minikube dashboard
*Enabling dashboard...
* Verifying dashboard health...
*Launching proxy...
* Verifying proxy health...
http://127.0.0.1:46658/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

By default, only local access is available. Set up a proxy to allow external access (the foreground operation cannot be exited)

[root@k8s-host ~]# kubectl proxy --port=33458 --address='0.0.0.0' --accept-hosts='^.*' & amp;
[1] 28883
[root@k8s-host ~]# Starting to serve on [::]:33458

Set the cloud server port:

External computer access (public network IP)

http://121.37.xxx.xx:33458/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=default

Practice: After the k8s environment in the cloud server is set up, you can back up a private image, restore it on the new cloud server, modify the host name, turn off the firewall, etc. The startup command is as follows:

 minikube start --vm-driver=none --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --kubernetes-version v1.17.3 

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skills treeHomepageOverview 15,250 people are learning the system