Solution Kubeconfig
dev-userwants to accesstest-cluster-1, set the current context.- To use a specific context, run:
kubectl config --kubeconfig=/root/my-kube-config use-context research - Find out the current context:
kubectl config --kubeconfig=/root/my-kube-config current-context - How to set a custom KubeConfig file as the default one? In this example we want to overerite
~/.kube/configwithmy-kube-config. - Open
bashrc:vim ~/.bashrc - Export the variable with this line:
export KUBECONFIG=/root/my-kube-config - Then
source~/.bashrc:source ~/.bashrc - With a specific cluster’s context set to
research, there are problems when accessing the cluster. - Running
kubectl get podsshows the following:controlplane ~ ➜ kubectl get pods error: unable to read client-cert /etc/kubernetes/pki/users/dev-user/developer-user.crt for dev-user due to open /etc/kubernetes/pki/users/dev-user/developer-user.crt: no such file or directory - Check the contents of
~/.kube/config - Check the
/etc/kubernetes/pki/users/dev-user/developer-user.crt - Edit the
~/.kube/configfile -
Then commands such as
kubectl get nodeswill work. - How to find the home directory:
echo $HOME - How to change to a specific context:
kubectl config use-context research --kubeconfig /root/my-kube-config - To set a custom KubeConfig file as the Default Config, overwrite the default file with:
mv <custom_config_file> ~/.kube/config - Check the configuration with
kubectl config view