Adaltas Cloud Academy
Sign out >

Kubectl

kubectl is the go-to tool to interact with a Kubernetes cluster.

Tutorial objectives

In this tutorial you will:

  • Learn how to configure your environment to use kubectl
  • Discover the kubectl basic commands

[[info | Setup Kubernetes and login first]] | Before interacting with Kubernetes, your environnment must be configured and you shall be authenticated. Read the Kubernetes onboarding instructions to get started.

kubectl basic commands

Here some basic kubectl commands.

Note: you only have access to the resources of your namespace (which is your group name), thus we will add -n adaltas to every command. adaltas is an example group/namespace please replace it with your group name (ex: teachers).

List pods:

kubectl get pods -n adaltas

NAME                                                          READY     STATUS    RESTARTS   AGE
adaltas-elastic-stack-elasticsearch-client-586f4d5c64-l8lhn   1/1       Running   0          8m
adaltas-elastic-stack-elasticsearch-data-0                    1/1       Running   0          8m
adaltas-elastic-stack-elasticsearch-master-0                  1/1       Running   0          8m
adaltas-elastic-stack-elasticsearch-master-1                  1/1       Running   0          7m
adaltas-elastic-stack-kibana-7df57f4df4-8z462                 1/1       Running   0          8m

Describe a pod:

kubectl describe pod adaltas-elastic-stack-elasticsearch-data-0 -n adaltas

Name:		adaltas-elastic-stack-elasticsearch-data-0
Namespace:	adaltas
Node:		k8s-2.au.adaltas.cloud/10.0.0.71
Start Time:	Thu, 02 Jul 2020 13:51:13 +0000
Labels:		app=elasticsearch
		component=data
		controller-revision-hash=adaltas-elastic-stack-elasticsearch-data-85b748bbd
		release=adaltas-elastic-stack
		role=data
		statefulset.kubernetes.io/pod-name=adaltas-elastic-stack-elasticsearch-data-0
Status:		Running
IP:		10.244.1.98
Controllers:	<none>
Containers:
  elasticsearch:
    Container ID:	docker://472dc588690663a7b732ef83539d5ddd143b785f95f9fb0b8b1cccaa30c44224
    Image:		docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.2
    Image ID:		docker-pullable://docker.elastic.co/elasticsearch/elasticsearch-oss@sha256:316be55cedc4a1d301e57344ebed8424a59e75ddb75bf7b6bb4c7779ed47f053
    Port:		9300/TCP
....

Print logs of a pod:

kubectl logs adaltas-elastic-stack-elasticsearch-data-0 -n adaltas

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2020-07-02T13:51:41,704][INFO ][o.e.e.NodeEnvironment    ] [adaltas-elastic-stack-elasticsearch-data-0] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/rbd1)]], net usable_space [14.5gb], net total_space [14.6gb], types [ext4]
[2020-07-02T13:51:41,710][INFO ][o.e.e.NodeEnvironment    ] [adaltas-elastic-stack-elasticsearch-data-0] heap size [1.4gb], compressed ordinary object pointers [true]
[2020-07-02T13:51:41,714][INFO ][o.e.n.Node               ] [adaltas-elastic-stack-elasticsearch-data-0] node name [adaltas-elastic-stack-elasticsearch-data-0], node ID [WuYtZ9ezSbakb8RW6V3NgA]
[2020-07-02T13:51:41,714][INFO ][o.e.n.Node               ] [adaltas-elastic-stack-elasticsearch-data-0] version[6.8.2], pid[1], build[oss/docker/b506955/2019-07-24T15:24:41.545295Z], OS[Linux/5.0.0-38-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/12.0.1/12.0.1+12]
....

Get PersistentStorageVolumes (PVCs):

kubectl get pvc -n adaltas

NAME                                                STATUS    VOLUME                                     CAPACITY   ACCESSMODES   AGE
data-adaltas-elastic-stack-elasticsearch-data-0     Bound     pvc-b8b3908b-d916-4bc2-b6c8-918f039cf140   15Gi       RWO           12m
data-adaltas-elastic-stack-elasticsearch-master-0   Bound     pvc-30d26f1b-7fee-4f63-9d15-f88a40ff195b   2Gi        RWO           12m
data-adaltas-elastic-stack-elasticsearch-master-1   Bound     pvc-098a761b-709f-4e5e-995e-5dea595cfde8   2Gi        RWO           11m