kubectl Commands

Installing from the terminal.

8 May 2023 · Read time 8 min

Installing kubectl

To use gcloud to install kubectl according to the Google GKE instructions:

gcloud components install kubectl
sudo apt-get install kubectl

Use curl to install kubectl according to the Kubernetes website:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

kubectl cluster-info dump

This is an expanded listing using the cluster info command (many hundreds of lines).

kubectl cluster-info dump

# Example response for a very long cluster information dump
# -----------------------------------------------------------
# {
#     "kind": "NodeList",
#     "apiVersion": "v1",
#     "metadata": {
#         "resourceVersion": "8685921"
#    },
#     "items": [
#         {
#             "metadata": {
#                 "name": "gke-cluster-1-default-pool-36e9706c-0fxb",
#                 "uid": "0b89edcc-d46b-4783-84f9-a7672f0bd922",
# ...
# ... several hundred lines
# ...
# 13. __clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
#  (version 21.8.10.1.altinitystable (altinity build))
# 2023.04.14 06:24:31.919921 [ 115 ] {} <Debug> DNSResolver: Updated DNS cache
# 2023.04.14 06:24:35.915268 [ 54 ] {} <Debug> DiskLocal: Reserving 1.00 MiB on disk `default`, having unreserved 97.44 GiB.
# ==== END logs for container clickhouse of pod default/chi-first-first-1-1-0 ====

kubectl exec - Enter a ClickHouse pod

To enter the pod and run the ClickHouse client directly, first locate the nodename of the cluster using the watch or k9s or find it from the ACM.

kubectl exec -it chi-first-first-0-0-0 -- bash

# You are now inside the pod, run a list command:
root@chi-first-first-0-0-0:/# ls

## bin  boot  cloud-connect.pem  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  kubectl  kubectl.sha256  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

# To exit out of the pod
exit
# ubuntu@ip-123-45-67-890:~$

kubectl get ns

This lists the currently registered Kubernetes namespaces in the current cluster-1 using the kubectl get ns command.

Data
Figure 3 - Running the kubectl get ns command to list all of the namespaces.


kubectl get pod

List the CPU pods in a ClickHouse cluster.

kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName

# Example response to list pods
# ------------------------------
# NAME                    STATUS    NODE
# chi-first-first-0-0-0   Running   gke-cluster-1-default-pool-36e9706c-xj7p
# chi-first-first-0-1-0   Running   gke-cluster-1-default-pool-aa3988ca-nth7
# chi-first-first-1-0-0   Running   gke-cluster-1-default-pool-36e9706c-0fxb
# chi-first-first-1-1-0   Running   gke-cluster-1-default-pool-36e9706c-wrbm

kubectl get pvc

List the storage volumes.

kubectl get pvc

# Example response to list volumes
# --------------------------------
# NAME                           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
# pd-ssd-chi-first-first-0-0-0   Bound    pvc-5bc72a03-2ae5-41d1-9e93-92b92829c435   100Gi      RWO            premium-rwo    8d
# pd-ssd-chi-first-first-0-1-0   Bound    pvc-ec8f143d-c51d-4125-938a-76ad103fb7f2   100Gi      RWO            premium-rwo    8d
# pd-ssd-chi-first-first-1-0-0   Bound    pvc-014d010b-d282-4b47-91ef-b332bd381a28   100Gi      RWO            premium-rwo    8d
# pd-ssd-chi-first-first-1-1-0   Bound    pvc-c11d5819-1935-4b6f-ad54-60fa196fe013   100Gi      RWO            premium-rwo    8d

kubectl get all -n zoo1ns

To list the Zookeeper nodes:

kubectl get all -n zoo1ns

# Example response to list zookeeper nodes and services
# -----------------------------------------------------
# NAME              READY   STATUS    RESTARTS   AGE
# pod/zookeeper-0   1/1     Running   0          8d
# 
# NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
# service/zookeeper    ClusterIP   10.72.131.73   <none>        2181/TCP,7000/TCP   8d
# service/zookeepers   ClusterIP   None           <none>        2888/TCP,3888/TCP   8d
# 
# NAME                         READY   AGE
# statefulset.apps/zookeeper   1/1     8d

kubectl describe storageclass

List Storage Classes. (See ACM 》 Resources Configuration 》 Storage Classes )

kubectl describe storageclass

# Example response to list all the storage
# ----------------------------------------
# Name:                  premium-rwo
# IsDefaultClass:        No
# Annotations:           components.gke.io/component-name=pdcsi,components.gke.io/component-version=0.13.7,components.gke.# io/layer=addon
# Provisioner:           pd.csi.storage.gke.io
# Parameters:            type=pd-ssd
# AllowVolumeExpansion:  True
# MountOptions:          <none>
# ReclaimPolicy:         Delete
# VolumeBindingMode:     WaitForFirstConsumer
# Events:                <none>
# 
# 
# Name:                  standard
# IsDefaultClass:        No
# Annotations:           components.gke.io/layer=addon,storageclass.kubernetes.io/is-default-class=false
# Provisioner:           kubernetes.io/gce-pd
# Parameters:            type=pd-standard
# AllowVolumeExpansion:  True
# MountOptions:          <none>
# ReclaimPolicy:         Delete
# VolumeBindingMode:     Immediate
# Events:                <none>
# 
# 
# Name:                  standard-rwo
# IsDefaultClass:        Yes
# Annotations:           components.gke.io/layer=addon,storageclass.kubernetes.io/is-default-class=true
# Provisioner:           pd.csi.storage.gke.io
# Parameters:            type=pd-balanced
# AllowVolumeExpansion:  True
# MountOptions:          <none>
# ReclaimPolicy:         Delete
# VolumeBindingMode:     WaitForFirstConsumer
# Events:                <none>

kubectl config view

To verify the config file is updated with the correct credentials, review it by running the kubctl config view command.

Data
Figure 1 - Running the kubctl config view.svg command to verify that the config file is updated with credentials.


gcloud container clusters list

This lists the current container information with the gcloud container clusters list command.

Data
Figure 2 - Running the gcloud container clusters list command.


kubectl clusterinfo

Run the kubectl clusterinfo command to list the Kubernetes control plan and services. At this point the Google set up is complete. Now you can use Altinity.Cloud Anywhere to connect Google GKE to the Altinity Cloud Manager.

Data
Figure 4 - Running the kubectl clusterinfo command.

kubectl version

The computer or cloud compute instance that you use to communicate with Google Cloud requires installation of the Google CLI and Kubernetes.

The following list of software needs to be installed:

  • kubectl (kubectl get namespaces)

version checks that some items you do not have

Checking Versions To make sure the prerequisites have been met, check the versions of the installed software.

# Version checks
kubectl version --short        # v1.27.1
cat /etc/os-release            # Ubuntu 20.04
altinitycloud-connect version  # Altinity 0.20.0
gcloud version                 # Google Cloud SDK 429.0.0
kubectl version --short
# Client Version: v1.26.3
# Kustomize Version: v4.5.7
# Unable to connect to the server: net/http: TLS handshake timeout

# Another variation to display version
kubectl version  --output=yaml

Last modified 2023.05.11: Added Google GKE Installation instructions