Connexion to k8s cluster

Kubeconfig

  • Define KUBECONFIG in your profile
1# Default one 
2KUBECONFIG=~/.kube/config
3
4# Several context - to keep splited 
5KUBECONFIG=~/.kube/k3sup-lab:~/.kube/k3s-dev
6
7# Or can be specified in command
8kubectl get pods --kubeconfig=admin-kube-config
  • View and Set
 1kubectl config view
 2kubectl config current-context
 3
 4kubectl config set-context \
 5dev-context \
 6--namespace=dev-namespace \
 7--cluster=docker-desktop \
 8--user=dev-user
 9
10kubectl config use-context lab
  • Switch context
1#set Namespace 
2kubectl config set-context --current --namespace=nexus3
3kubectl config get-contexts

Kubecm

The problem with the kubeconfig is that it get nexted in one kubeconfig and difficult to manage on long term. The best way to install it, is with Arkade arkade get kubecm - see arkade.

Here, the most usefull

1kubecm list 
2kubecm add -f new-cluster.yaml
3kubecm delete
4kubecm rename
5kubecm switch # Kubecm s (is also fine)
6kubecm export

Manage Secrets

  • Add Certificates in a Secrets
1kubectl create secret tls urls-tls --key="tls.key" --cert="tls.crt"  -n longhorn-system --dry-run=client -o yaml