Skip to content

K8s clients

To interact with a k8s cluster, you need at lest two clients: - kubectl - helm

1. kubectl

kubectl is a command line tool for communicating with a Kubernetes cluster's control plane, using the Kubernetes API.

For configuration, it looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag.

1.1 Installation

You can find the official doc here

You can follow the below steps to install it. Below instruction are tested for x86-64 architecture.

# 1. Download the binary with curl 
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# 2. Get the hash of the binary
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

# 3. validate the binary by checking the hash
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

# 4. copy bin to your local bin
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# 5. check the installation
kubectl version

# output example
Client Version: v1.31.2
Kustomize Version: v5.4.2
The connection to the server localhost:8080 was refused - did you specify the right host or port?

The default config is pointing to localhost:8080, we need to replace it with the k8s api server url.

1.2 Configuration

As we mentioned, the default config file is located at ``. Below is an example of the config content.

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: changeMe
    server: https://k8s-master:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: changeMe
    client-key-data: changeMe

You can notice the access control in the k8s cluster is RBAC.

Normally, the admin of the k8s cluster will provide you the login(username), and the credential(e.g. password, token, etc.)

You can find the official doc of API access control here

Helm

You can find the official installation doc here. You need to choose a version which is compatible with your k8s cluster and your local OS(e.g. linux-amd64, windows-amd64, etc.).

The available version can be found here.

For example, in below example, we choose version 3.16.2.

# get the source
wget https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz


tar -xzvf helm-v3.16.2-linux-amd64.tar.gz

chmod a+x linux-amd64/helm

mv linux-amd64/helm /usr/local/bin/helm

# add the bitnami repo
helm repo add bitnami https://charts.bitnami.com/bitnami

# show available charts in the bitnami repo
helm search repo bitnami

Check Artifact Hub for all public available Helm chart repositories.