K8s basic configuration


Installing kubectl

Using Tsinghua source

Red hat system

$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
$ yum install -y kubectl

Debian system

$ sudo apt-get update && sudo apt-get install -y apt-transport-https
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ echo "deb https://mirrors.tuna.tsinghua.edu.cn/kubernetes/apt kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
$ sudo apt-get update
$ sudo apt-get install -y kubectl

to configure

View version

kubectl version


Check that kubectl is configured correctly by getting the cluster state

kubectl cluster-info

If kubels is correctly configured, then you can see that kubels is returned to the cluster.

If you see information like the following being returned, kubectl is not configured correctly to properly access your kubernetes cluster.

The connection to the server <server-name:port> was refused - did you specify the right host or port?

For example, if you plan to run a kubernetes cluster on a laptop (local), you need to first install tools such as minikube, and then rerun the above command.

If kubectl cluster info can return a URL response, but you cannot access your cluster, you can use the following command to check whether the configuration is correct:

kubectl cluster-info dump




Install using snap

sudo snap install microk8s --classic

Start and view the status of the microk8s:

Sudo microk8s. Start // start microk8s
Microk8s status -- wait ready // query the current status

Since it is a single node k8s, kubectl can be directly integrated into alias
modify~/.bash_aliasesAdd the following
alias kubectl='microk8s kubectl'

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]