Installing kubectl
Using Tsinghua source
Red hat system
$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=```
https://mirrors.tuna.tsinghua.edu.cn/kubernetes/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
$ 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
inspect
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
Minikube
https://kubernetes.io/zh/docs…
Microk8s
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_aliases
Add the followingalias kubectl='microk8s kubectl'