Here are some notes and few tests while going through the book “The Kubernetes Book” from Nigel Poulton.
Checking Kubernetes Nodes
❯ kubectl get nodes
NAME STATUS ROLES AGE VERSION
mke-manager-0 Ready master 27d v1.20.11-mirantis-1
mke-manager-1 Ready master 27d v1.20.11-mirantis-1
mke-manager-2 Ready master 27d v1.20.11-mirantis-1
mke-node-0 Ready <none> 27d v1.20.11-mirantis-1
mke-node-1 Ready <none> 27d v1.20.11-mirantis-1
Defining Manifest
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
name: v1
spec:
containers:
- name: hello-ctr
image: nigelpoulton/k8sbook:1.0
ports:
- containerPort: 8080
Creating Pod
❯ kubectl apply -f pod.yml
pod/hello-pod created
❯ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 0/1 ContainerCreating 0 9s
❯ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 1/1 Running 0 10s
Kubectl Get
❯ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hello-pod 1/1 Running 0 9m10s 192.168.64.75 mke-node-1 <none> <none>
kubectl get pods hello-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"name":"v1"},"name":"hello-pod","namespace":"default"},"spec":{"containers":[{"image":"nigelpoulton/k8sbook:1.0","name":"hello-ctr","ports":[{"containerPort":8080}]}]}}
kubernetes.io/psp: privileged
seccomp.security.alpha.kubernetes.io/pod: docker/default
creationTimestamp: "2022-03-14T13:56:32Z"
labels:
name: v1
name: hello-pod
namespace: default
resourceVersion: "924087"
uid: 246507d1-bbfd-4d69-ad80-835e6ee8222a
spec: <<<============================================== Desired state section
containers:
- image: nigelpoulton/k8sbook:1.0
imagePullPolicy: IfNotPresent
name: hello-ctr
ports:
- containerPort: 8080
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
(OMMITED OUTPUT)
status: <<<============================================== Observed state section
conditions:
- lastProbeTime: null
lastTransitionTime: "2022-03-14T13:56:32Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2022-03-14T13:56:42Z"
status: "True"
type: Ready
- lastProbeTime: null
The previous command should show a YAML manifest that represents the pod. It is interesting to see the “.spec” and “.status” sections. representing the “desired state” and “observed state” respectfully.
Kubectl Describe
❯ kubectl describe pods hello-pod
Name: hello-pod
Namespace: default
Priority: 0
Node: mke-node-1/10.0.14.145
Start Time: Mon, 14 Mar 2022 14:56:32 +0100
Labels: name=v1
Annotations: kubernetes.io/psp: privileged
seccomp.security.alpha.kubernetes.io/pod: docker/default
Status: Running
IP: 192.168.64.75
IPs:
IP: 192.168.64.75
Containers:
hello-ctr:
Container ID: docker://3ab6bdb11b7af5744fc7f71f1728174a1864c28cd5ab6ea4ed8daac7da03d36d
Image: nigelpoulton/k8sbook:1.0
Image ID: docker-pullable://nigelpoulton/k8sbook@sha256:a983a96a85151320cd6ad0cd9fda3b725a743ed642e58b0597285c6bcb46c90f
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 14 Mar 2022 14:56:41 +0100
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9xs78 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-9xs78:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9xs78
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 21m default-scheduler Successfully assigned default/hello-pod to mke-node-1
Normal Pulling 21m kubelet Pulling image "nigelpoulton/k8sbook:1.0"
Normal Pulled 21m kubelet Successfully pulled image "nigelpoulton/k8sbook:1.0" in 5.472383155s
Normal Created 21m kubelet Created container hello-ctr
Normal Started 21m kubelet Started container hello-ctr
Kubectl Logs
❯ kubectl logs hello-pod
Kubectl Exec
❯ kubectl exec hello-pod -- ps aux
PID USER TIME COMMAND
1 root 0:00 node ./app.js
12 root 0:00 ps aux
❯ kubectl exec -it hello-pod -- sh
/src # uname
Linux
/src # env | grep -i hostname
HOSTNAME=hello-pod
Inmutability
❯ kubectl edit pod hello-pod
A copy of your changes has been stored to "/var/folders/c8/zsg8_qln263_1fs01sftdyfw0000gn/T/kubectl-edit-3391211217.yaml"
error: At least one of apiVersion, kind and name was changed