Kubernetes Basics
Install kubectl
.
NB: Debian requires manual installation.1
Read
- Check the namespace:
kubectl get namespaces
- Check the
${kube-system}
namespace: `kubectl get deployments.apps --namespace kube-system' - Check host computers:
kubectl get nodes
- Check pods:
kubectl get pods
1Namespaces
2├── Node_1: minikube
3│ ├── deployment_1: nginx
4│ │ ├── pod_1
5│ │ └── pod_2
6│ ├── deployment_2: database
7│ │ ├── pod_1
8│ │ ├── pod_2
9│ │ ├── pod_3
10│ │ └── pod_4
11│ ├── deployment_3: prometheus
12│ └── deployment_4: idk probably yaml
13└── Node_1: physical server
14 ├── deployment_1: nginx
15 │ ├── pod_1
16 │ └── pod_2
17 ├── deployment_2: database
18 │ ├── pod_1
19 │ ├── pod_2
20 │ ├── pod_3
21 │ └── pod_4
22 ├── deployment_3: prometheus
23 └── deployment_4: Abandoned wiki
More Information
1 $ kubectl get pod
2
3NAME READY STATUS RESTARTS AGE
4nginx-depl-68c944fcbc-2xbvq 1/1 Running 0 20m
5
6 $ kubectl describe pod nginx-depl-68c944fcbc-2xbvq
7
8Name: nginx-depl-68c944fcbc-2xbvq
9Namespace: default
10Priority: 0
11Service Account: default
12Node: minikube/192.168.59.107
13Start Time: Fri, 29 Aug 2025 19:26:29 +0200
14Labels: app=nginx-depl
15 pod-template-hash=68c944fcbc
16Annotations: <none>
17Status: Running
18IP: 10.244.0.3
19IPs:
20 IP: 10.244.0.3
21Controlled By: ReplicaSet/nginx-depl-68c944fcbc
22Containers:
23 nginx:
24 Container ID: docker://aaa68e90ed9237dc0f98f9a21b0d7ddf3113188c62e72242d30cab4a43cbff98
25 Image: nginx
26 Image ID: docker-pullable://nginx@sha256:33e0bbc7ca9ecf108140af6288c7c9d1ecc77548cbfd3952fd8466a75edefe57
27 Port: <none>
28 Host Port: <none>
29 State: Running
30 Started: Fri, 29 Aug 2025 19:26:41 +0200
31 Ready: True
32 Restart Count: 0
33 Environment: <none>
34 Mounts:
35 /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9bgxx (ro)
36Conditions:
37 Type Status
38 PodReadyToStartContainers True
39 Initialized True
40 Ready True
41 ContainersReady True
42 PodScheduled True
43Volumes:
44 kube-api-access-9bgxx:
45 Type: Projected (a volume that contains injected data from multiple sources)
46 TokenExpirationSeconds: 3607
47 ConfigMapName: kube-root-ca.crt
48 Optional: false
49 DownwardAPI: true
50QoS Class: BestEffort
51Node-Selectors: <none>
52Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
53 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
54Events:
55 Type Reason Age From Message
56 ---- ------ ---- ---- -------
57 Normal Scheduled 24m default-scheduler Successfully assigned default/nginx-depl-68c944fcbc-2xbvq to minikube
58 Normal Pulling 24m kubelet Pulling image "nginx"
59 Normal Pulled 24m kubelet Successfully pulled image "nginx" in 11.204s (11.204s including waiting). Image size: 192385800 bytes.
60 Normal Created 24m kubelet Created container: nginx
61 Normal Started 24m kubelet Started container nginx
Pod copies are called a 'replicaset'.
1 $ kubectl exec $POD_NAME -- env
2
3PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
4HOSTNAME=stupendously-verbose-podish-nomenclature-jvguenaqbz-punenpgref
5KUBERNETES_PORT_443_TCP_PORT=443
6KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
7KUBERNETES_SERVICE_HOST=10.96.0.1
8KUBERNETES_SERVICE_PORT=443
9KUBERNETES_SERVICE_PORT_HTTPS=443
10KUBERNETES_PORT=tcp://10.96.0.1:443
11KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
12KUBERNETES_PORT_443_TCP_PROTO=tcp
13NPM_CONFIG_LOGLEVEL=info
14NODE_VERSION=6.3.1
15HOME=/root
Create
Create a 'deployment' of nginx
.
1name="nginx-depl"
2kubectl create deployment ${name} --image=nginx
3kubectl get deployments
The command did not specify a namespace, so default
is used.
Update
Update a deployment, with $EDITOR
.
1kubectl edit deployments.apps ${name}
This gives us far too much information:
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 annotations:
5 deployment.kubernetes.io/revision: "1"
6
7 [ ... ]
8
9 creationTimestamp: "2025-08-29T18:13:45Z"
10 generation: 3
11 labels:
12 app: nginx-depl
13 name: nginx-depl
14 namespace: default
15 resourceVersion: "17696"
16 uid: 8dec2925-5c34-4635-b82c-ba601cb3bef5
17spec:
18 progressDeadlineSeconds: 600
19 replicas: 2
20 revisionHistoryLimit: 10
21 selector:
22 matchLabels:
23 app: nginx-depl
24
25 [ ... ]
26
27 observedGeneration: 3
28 readyReplicas: 2
29 replicas: 2
30 updatedReplicas: 2
Pull out the information, without an $EDITOR
:
1file="webstuff"
2kubectl get deployment ${name} -o yaml > ${webstuff}.yaml
Enter the Pod
1 $ kubectl get pods
2
3NAME READY STATUS RESTARTS AGE
4nginx-depl-68c944fcbc-2xbvq 1/1 Running 0 31m
5
6 $ pod='nginx-depl-68c944fcbc-2xbvq'
7 $ kubectl exec -it ${pod} -- bash
8
9 root@nginx-depl-68c944fcbc-2xbvq:/# ls
10 bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
11 boot docker-entrypoint.d etc lib media opt root sbin sys usr
12 root@nginx-depl-68c944fcbc-2xbvq:/#
13 exit
Delete
Delete a deployment, and watch it leave:
1name=nginx-depl
2kubectl delete deployments.apps nginx-depl && kubectl get deployments.apps
3kubectl get deployments.apps