Back

How to access a Kubernetes cluster

To access and execute commands in a Kubernetes cluster, you can use the kubectl command-line utility. It allows you to deploy applications, manage cluster resources and view event logs.

The utility is cross-platform and can be installed on various operating systems, including Linux, macOS, and Windows.

For more detailed information, including a full list of available commands, refer to the official documentation.

Getting started with kubectl

To avoid unexpected issues, ensure that the kubectl version differs from the cluster version by no more than one minor version.

For example, a client running version v1.31 can interact with control planes running versions v1.30, v1.31, and v1.32.

To check the client version:

  1. Go to the customer portal

  2. In the left-hand menu, navigate to Kubernetes and select your cluster

  3. The cluster version will be displayed in the Version field

Installing kubectl

This guide provides step-by-step instructions on how to install kubectl on macOS using curl.

For other operating systems, refer to the official documentation.

Installing the kubectl binary with curl on macOS

  1. Download the suitable version by executing the following command in the terminal:

    curl -LO https://dl.k8s.io/release/{version}/bin/darwin/{CPU}/kubectl

    Replace:

    • {version} with the required version, e.g., v1.31.0

    • {CPU} with the correct architecture:

      • For Intel: use amd64

      • For Apple Silicon: use arm64

  2. Validate the binary file (optional):

    • Download the checksum file:

      curl -LO https://dl.k8s.io/release/{version}/bin/darwin/{CPU}/kubectl.sha256
    • Validate the binary against the checksum:

      echo "$(cat kubectl.sha256)  kubectl" | shasum -a 256 --check
    • If successful, the output will display:

      kubectl: OK
    • If the check fails, you will see:

      kubectl: FAILED
      shasum: WARNING: 1 computed checksum did NOT match
      
    • Download the same version of the binary and try again

  3. Make the kubectl binary executable:

    chmod +x ./kubectl
  4. Move the kubectl binary to a directory included in your system PATH by executing the following commands:

    sudo mv ./kubectl /usr/local/bin/kubectl
    sudo chown root: /usr/local/bin/kubectl
    

    Note: ensure /usr/local/bin is included in your PATH environment variable. If you receive an error such as No such file or directory, create the directory using the following command:

    sudo mkdir -p /usr/local/bin
  5. Verify the installed version:

    kubectl version --client

If successful, the output will display the version of the kubectl client.

Configuring KUBECONFIG

To use the kubectl utility with a Kubernetes cluster, you need a configuration file (kubeconfig). This allows you to locate and access one or multiple clusters and seamlessly switch between them. For more details, refer to the official documentation.

  1. Download the configuration file for your cluster from the Kubernetes cluster details page in the customer portal:

Kubernetes cluster details in portal
  1. Export the KUBECONFIG environment variable, specifying the path to the configuration file:

    export KUBECONFIG={path to config file}
  2. Ensure that kubectl is properly configured by getting the cluster information:

    kubectl cluster-info

Suggested Articles

  • Kubernetes clusters

    Creating a cluster

  • Kubernetes clusters

    Adding and removing worker nodes