Kubernetes X509 certification issue while executing kubectl

Problem

Getting the following error while executing kubectl commands. Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")

Cause

Default kubernetes configuration file  - /etc/kubernetes/admin.conf is not copied to home location reference (either $HOME/.kube/config or $HOME/admin.conf) after executing "kubeadm init"

Fix

Run the below commands as non-root user. To copy the kubernetes cluster configuration to $HOME/.kube/config

       To start using your cluster, run below commands:

          mkdir -p $HOME/.kube

          sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

          sudo chown $(id -u):$(id -g) $HOME/.kube/config

          export KUBECONFIG=$HOME/.kube/config

Add “export KUBECONFIG=$HOME/.kube/config” to ~/.bashrc file in order to export the conf file. If this is not added, the export will be applicable only to the current putty session. For a new session, the Kubernetes API will be unreachable.

(OR)

Run the below commands as root user. To copy the kubernetes cluster configuration to $HOME/admin.conf

    To start using your cluster, run below commands as root user or prefix with sudo:

          cp /etc/kubernetes/admin.conf $HOME/

          chown $(id -u):$(id -g) $HOME/admin.conf

          export KUBECONFIG=$HOME/admin.conf

Add “export KUBECONFIG=$HOME/admin.conf” to ~/.bashrc file in order to export the conf file. If this is not added, the export will be applicable only to the current putty session. For a new session, the Kubernetes API will be unreachable.