Kubernetes cluster access

Page contains information about obtaining kubernetes cluster access

Access kubernetes cluster from the server (ssh connection)

Kubernetes configuration file is stored on server at users home directory ~/.kube/config

All user accounts added to inventory files (infrastructure/server-setup/inventory) already have kubernetes access.

Once you logged in on the server use kubectl utility to access cluster.

Configure kubectl locally to work with remote cluster

Kubernetes gives you an option to interact with cluster remotely using kubectl utility [1]. You will need to have a Kubernetes cluster account to work remotely and configure kubectl to work with your remote cluster.

Transfer kubectl configuration file (~/.kube/config same as /home/<username>/.kube/config) from server to your laptop (or PC).

Example scp command: Command will transfer file from remote server 10.1.1.21 users bob home directory (/home/bob/.kube/config) into temporal directory (/tmp/kubeconfig). If ssh is running on non-default port, you may change it by add -P <port number>. Private key is defined as -i ~/.ssh/id_rsa

scp -P 22 -i ~/.ssh/id_rsa [email protected]:~/.kube/config /tmp/kubeconfig

Option 1: Use the /tmp/kubeconfig temporarily

  1. Open terminal window

  2. Set environment variable:

    export KUBECONFIG=/tmp/kubeconfig
  3. Run any command, e/g:

    kubectl get namespaces

Option 2: Make cluster connection your default kubeconfig

  1. Check if you already have any kubeconfig on your laptop:

  2. If you don't have any other clusters, you can run:

This will overwrite your existing default configuration. If you want to keep multiple cluster connections in the same file, you may need to add configuration manually, please search in google for more details.

Option 3: Add new cluster to your default kubeconfig

If you already have ~/.kube/config on your laptop run following command to append new cluster to your existing configuration:

{% hint style="warning" %} Sometime cluster with the same context may already exist in your local configuration file, you may get error:

In that case backup kubernetes config file located on your laptop at ~/.kube/config and remove it. Run mv /tmp/kubeconfig ~/.kube/config after. {% endhint %}### Connecting to cluster remotely

Verify cluster connection

  1. Check existing clusters:

    Example output

  2. Change cluster context:

    Example output:

[1] https://kubernetes.io/docs/reference/kubectl/quick-reference/

Last updated