centos install kubectl tools and minikube

kubectl and minikube are two important tools to deploy kubernetes clusters, this article describes how to install these two tools.

Installation Environment: centos7 virtual machine

First, install kubectl

kubectl is k8s command-line tool, used in k8s cluster, you can deploy applications, view and manage cluster resources. Use kubectl version can not be too different version with a cluster, it is best to use the latest version of kubectl.

1. Download the installation package, the following two commands, a first download the latest version, to download the specified second version

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

2.kubectl not execute, execute permissions increase

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

chmod +x kubectl
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

3. The installation package is moved to the directory path

mv ./kubectl /usr/local/bin/kubectl
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

4. View the version is not the latest version

kubectl version --client
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

 

Second, the installation docker hypervisor

Because the local installation environment is to use a virtual machine, so the longer virtual.

It is recommended to install VirtualBox

Using yum installation, the installation method:

Creating /etc/yum.repos.d/virtualbox.repo file, as follows:

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

After performing

yum install VirtualBox-6.0
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

 

After the selection has been "y" is complete

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Third, the installation Minikube

1.Minikube this tool supports k8s cluster virtual machines running on a single node

Before starting the installation, first check whether the local machine to support virtualization, to support an output

grep -E --color 'vmx|svm' /proc/cpuinfo
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

I use the machine is to use vmware isolate a virtual machine on windows, as shown in the second section is no longer installed on the virtual machine tool.

Virtual machine executes the above command is not output, the following method may be employed to support virtualization.

Reopen after turning off the virtual machine, select the following selection of the virtual machine of FIG.

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

2. Installation minikube 3 methods, package package installation binary files to install and use homebrew installation, where I used binary packages installed, execute the following command to download

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Add the path to the executable file minikube

sudo mkdir -p /usr/local/bin/sudo install minikube /usr/local/bin/

3. 启动 minikube

minikube start --vm-driver=virtualbox
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Given as follows:

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Look meaning inside the virtual machine running, the parameter value is equal to none

minikube start --vm-driver=none
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Error again

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Turn off the virtual machine and re-set the number of CPU

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

4. Start minikube again

minikube start --vm-driver=none
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==Replace Ali cloud images, re-execute the command to start

minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --vm-driver=none
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

This process will download kubectl, kubelet, kubeadm three mirrors, about 400M, so slow, be patient. Automatically activated after downloading

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Error again, seen from the error, apiserver failed to start, you can confirm with the command: minikube status

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Access to online information, some believe that swap is not closed. swapoff -a close the swap, continue minikube start command continues to fail. 

Execution minikube delete, execute the command to start again, this time there have been many error log:

X 开启 cluster 时出错: init failed. output: "-- stdout --\n[init] Using Kubernetes version: v1.17.3\n[preflight] Running pre-flight checks\n[preflight] Pulling images required for setting up a Kubernetes cluster\n[preflight] This might take a minute or two, depending on the speed of your internet connection\n[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'\n[kubelet-start] Writing kubelet environment file with flags to file \"/var/lib/kubelet/kubeadm-flags.env\"\n[kubelet-start] Writing kubelet configuration to file \"/var/lib/kubelet/config.yaml\"\n[kubelet-start] Starting the kubelet\n[certs] Using certificateDir folder \"/var/lib/minikube/certs\"\n[certs] Using existing ca certificate authority\n[certs] Using existing apiserver certificate and key on disk\n[certs] Generating \"apiserver-kubelet-client\" certificate and key\n[certs] Generating \"front-proxy-ca\" certificate and key\n[certs] Generating \"front-proxy-client\" certificate and key\n[certs] Generating \"etcd/ca\" certificate and key\n[certs] Generating \"etcd/server\" certificate and key\n[certs] etcd/server serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]\n[certs] Generating \"etcd/peer\" certificate and key\n[certs] etcd/peer serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]\n[certs] Generating \"etcd/healthcheck-client\" certificate and key\n[certs] Generating \"apiserver-etcd-client\" certificate and key\n[certs] Generating \"sa\" key and public key\n[kubeconfig] Using kubeconfig folder \"/etc/kubernetes\"\n[kubeconfig] Writing \"admin.conf\" kubeconfig file\n[kubeconfig] Writing \"kubelet.conf\" kubeconfig file\n[kubeconfig] Writing \"controller-manager.conf\" kubeconfig file\n[kubeconfig] Writing \"scheduler.conf\" kubeconfig file\n[control-plane] Using manifest folder \"/etc/kubernetes/manifests\"\n[control-plane] Creating static Pod manifest for \"kube-apiserver\"\n[control-plane] Creating static Pod manifest for \"kube-controller-manager\"\n[control-plane] Creating static Pod manifest for \"kube-scheduler\"\n[etcd] Creating static Pod manifest for local etcd in \"/etc/kubernetes/manifests\"\n[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory \"/etc/kubernetes/manifests\". This can take up to 4m0s\n[kubelet-check] Initial timeout of 40s passed.\n[kubelet-check] It seems like the kubelet isn't running or healthy.\n[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.\n\nUnfortunately, an error has occurred:\n\ttimed out waiting for the condition\n\nThis error is likely caused by:\n\t- The kubelet is not running\n\t- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)\n\nIf you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:\n\t- 'systemctl status kubelet'\n\t- 'journalctl -xeu kubelet'\n\nAdditionally, a control plane component may have crashed or exited when started by the container runtime.\nTo troubleshoot, list all containers using your preferred container runtimes CLI, e.g. docker.\nHere is one example how you may list all Kubernetes containers running in docker:\n\t- 'docker ps -a | grep kube | grep -v pause'\n\tOnce you have found the failing container, you can inspect its logs with:\n\t- 'docker logs CONTAINERID'\n\n-- /stdout --\n** stderr ** \nW0227 14:11:35.372509   50864 validation.go:28] Cannot validate kube-proxy config - no validator is available\nW0227 14:11:35.372637   50864 validation.go:28] Cannot validate kubelet config - no validator is available\n\t[WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly\n\t[WARNING FileExisting-socat]: socat not found in system path\nW0227 14:11:42.309644   50864 manifests.go:214] the default kube-apiserver authorization-mode is \"Node,RBAC\"; using \"Node,RBAC\"\nW0227 14:11:42.313619   50864 manifests.go:214] the default kube-apiserver authorization-mode is \"Node,RBAC\"; using \"Node,RBAC\"\nerror execution phase wait-control-plane: couldn't initialize a Kubernetes cluster\nTo see the stack trace of this error execute with --v=5 or higher\n\n** /stderr **": /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.17.3:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,SystemVerification": exit status 1
stdout:
[init] Using Kubernetes version: v1.17.3
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[certs] Using certificateDir folder "/var/lib/minikube/certs"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.

Unfortunately, an error has occurred:
        timed out waiting for the condition

This error is likely caused by:
        - The kubelet is not running
        - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
        - 'systemctl status kubelet'
        - 'journalctl -xeu kubelet'

Additionally, a control plane component may have crashed or exited when started by the container runtime.
To troubleshoot, list all containers using your preferred container runtimes CLI, e.g. docker.
Here is one example how you may list all Kubernetes containers running in docker:
        - 'docker ps -a | grep kube | grep -v pause'
        Once you have found the failing container, you can inspect its logs with:
        - 'docker logs CONTAINERID'

stderr:
W0227 14:11:35.372509   50864 validation.go:28] Cannot validate kube-proxy config - no validator is available
W0227 14:11:35.372637   50864 validation.go:28] Cannot validate kubelet config - no validator is available
        [WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly
        [WARNING FileExisting-socat]: socat not found in system path
W0227 14:11:42.309644   50864 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
W0227 14:11:42.313619   50864 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

* 
* 由于出错 minikube 正在退出。如果以上信息没有帮助,请提交问题反馈:
  - https://github.com/kubernetes/minikube/issues/new/choose
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Large amount of information, but it's hard to figure out why. Combined with the current status quo: apiserver failed to start, error log a look back:

error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

Internet search phrase, there are many articles, some of the proposed closure SELINUX, close SELINUX, restart, really take effect, after the restart boot directly into apiserver

 

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw ==

References:

1.https://kubernetes.io/docs/tasks/tools/install-minikube/

2.https://www.itzgeek.com/how-tos/linux/centos-how-tos/install-virtualbox-4-3-on-centos-7-rhel-7.html

3.https://kubernetes.io/docs/tasks/tools/install-kubectl/#download-as-part-of-the-google-cloud-sdk

4.https://forum.level1techs.com/t/kubeadm-for-kubernetes-chicken-and-egg-problem-during-setup-what-am-i-doing-wrong/129086/4

 

                 the public

Published 33 original articles · won praise 2 · views 40000 +

Guess you like

Origin blog.csdn.net/zjj2006/article/details/104580562