Skip to content

Connecting with kubectl

kubectl talks to a cluster using a kubeconfig file. In Hyperkub you get one by creating a cluster credential.

A credential is issued per person or per machine, not per cluster. That means you can revoke one laptop’s access without disturbing anyone else, and you can see which credentials exist for a cluster.

Credentials are also short-lived. Expect to reissue them periodically rather than storing one forever.

  1. Open the cluster in the control plane.
  2. Go to Credentials → Create credential.
  3. Download the file when prompted.

For a single cluster, the simplest approach is an environment variable:

Terminal window
export KUBECONFIG=~/.kube/hyperkub-production.yaml
kubectl get nodes

To make it the default, save it as ~/.kube/config instead.

KUBECONFIG accepts a list, and kubectl merges the files:

Terminal window
export KUBECONFIG=~/.kube/config:~/.kube/hyperkub-production.yaml

List what merged, then switch between them:

Terminal window
kubectl config get-contexts
kubectl config use-context hyperkub-production

To avoid running the right command against the wrong cluster, set the context per command instead of switching globally:

Terminal window
kubectl --context hyperkub-staging get pods

Do not commit the kubeconfig. Store its contents in a masked CI variable and write it to disk at job start:

deploy:
script:
- echo "$KUBECONFIG_PRODUCTION" > "$CI_PROJECT_DIR/kubeconfig"
- export KUBECONFIG="$CI_PROJECT_DIR/kubeconfig"
- kubectl rollout restart deployment/api

Issue a dedicated credential for CI so it can be revoked independently of anyone’s laptop.

Unable to connect to the server: dial tcp ... i/o timeout

Section titled “Unable to connect to the server: dial tcp ... i/o timeout”

The cluster is probably not running yet. Check its status in the control plane — a cluster in provisioning does not answer.

error: You must be logged in to the server (Unauthorized)

Section titled “error: You must be logged in to the server (Unauthorized)”

The credential has expired or been revoked. Create a new one.

You are connected, but the pool has no nodes. Check the pool’s node count.

You have several files merged and the active context is not the one you meant. Run kubectl config current-context to confirm.