Kubectl
Install
Debian-based distributions:
-
Update the apt package index and install packages needed to use the Kubernetes apt repository:
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl -
Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:
# If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg -
Add the appropriate Kubernetes apt repository. If you want to use Kubernetes version different than v1.29, replace v1.29 with the desired minor version in the command below:
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list -
Update apt package index, then install kubectl:
sudo apt-get update
sudo apt-get install -y kubectl -
Verify kubectl version
kubectl version
Configuration
- By default, kubectl configuration is located at
~/.kube/config
. (File created automatically when you create a cluster, for example deploy Minikube or k3s)
Check that kubectl is properly configured by getting the cluster state:
kubectl cluster-info
Source: Official documentation
Manage kubernetes cluster
- Manage kubernetes cluster running on different machine from localhost
Example:
- Install k3s on Raspberry Pi
- Connect to RPi
- Copy file from RPi
/etc/rancher/k3s/k3s.yaml
to localhost~/.kube/config
scp tritoxid@rpi3:/etc/rancher/k3s/k3s.yaml ~/.kube/config
- Chnage IP address from localhost to machine IP
vim ~/.kube/config
server: https://xxx.xxx.xxx.xxx:6443 - You can change
default
cluster name and user to something else. - Check configuration
Correct output:
kubectl cluster-info
Kubernetes control plane is running at https://xxx.xxx.xxx.xxx:6443
CoreDNS is running at https://xxx.xxx.xxx.xxx:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://xxx.xxx.xxx.xxx:6443/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy