How to use kubeconfig to access to remote Kubernetes cluster
Install kubectl binary
The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
1 | [root@localhost ~]# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" |
Use kubeconfig file to access remote Kubernetes cluster
A kubeconfig is a YAML file with all the Kubernetes cluster details, certificate, and secret token to authenticate the cluster. You might get this config file directly from the cluster administrator or from a cloud platform if you are using managed Kubernetes cluster. A kubeconfig file is a file to configure access to Kubernetes when to use with kubectl cli tool.
When to deploy Kubernetes cluster, a kubeconfig is automatically generated. It’s saved in ~/.kube/config drectory.
1 | [root@host1 ~]# ls -la ~/.kube/config |
You can access the Kubernetes cluster by providing the kubeconfig file remotely.
1 | [root@localhost ~]# scp host1:/root/.kube/config ./kubeconfig-remote |