Using kubeconfig to configure 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.

[root@localhost ~]# curl -LO "$(curl -L -s"
[root@localhost ~]# sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
[root@localhost ~]# ls -la /usr/local/bin/kubectl
[root@localhost ~]# kubectl version --output=yaml
  buildDate: "2022-09-21T14:33:49Z"
  compiler: gc
  gitCommit: 5835544ca568b757a8ecae5c153f317e5736700e
  gitTreeState: clean
  gitVersion: v1.25.2
  goVersion: go1.19.1
  major: "1"
  minor: "25"
  platform: linux/amd64
kustomizeVersion: v4.5.7

The connection to the server localhost:8080 was refused - did you specify the right host or port?

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.

[root@host1 ~]#  ls -la ~/.kube/config
-rw------- 1 root root 5577 May  9 02:25 /root/.kube/config

You can access the Kubernetes cluster by providing the kubeconfig file remotely.

[root@localhost ~]# scp host1:/root/.kube/config ./kubeconfig-remote
[root@localhost ~]# kubectl --kubeconfig=./kubeconfig-remote get nodes
host0   Ready    <none>   135d   v1.19.2
host1   Ready    <none>   135d   v1.19.2
host2   Ready    <none>   135d   v1.19.2
host3   Ready    master   135d   v1.19.2