(1) Add a third k8s node DebianNode2:
(21:35 dabs@CNU1343VF8 ~) > kubectl get nodes
NAME STATUS ROLES AGE VERSION
cnu1343vf8 Ready master 17d v1.18.3
debiannode Ready <none> 16d v1.18.3
debiannode2 Ready <none> 2m13s v1.18.3
How to?
1, shut down DebianNode, clone it to a fresh new vm.
2, change hostname from 'DebianNode' to 'DebianNode2'
$sudo hostnamectl set-hostname DebianNode2
$sudo vim /etc/hosts
(2) Hands on with Pods
from <The k8s book>, difference between vm/container/pod:
Virtualization does VMs, Docker does containers, and Kubernetes does Pods
(00:30 dabs@CNU1343VF8 k8sbook) > kubectl delete -f pod.yml
pod "hello-pod" deleted
(00:46 dabs@CNU1343VF8 k8sbook) > kubectl apply -f pod.yml
pod/hello-pod created
(00:47 dabs@CNU1343VF8 k8sbook) > kubectl get pods --watch -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hello-pod 0/1 Pending 0 16s <none> <none> <none> <none>
hello-pod 0/1 Pending 0 53s <none> debiannode <none> <none>
hello-pod 0/1 ContainerCreating 0 53s <none> debiannode <none> <none>
hello-pod 1/1 Running 0 54s 10.244.1.7 debiannode <none> <none>
For the pod.yml, I have added "imagePullPolicy" to containers:
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
zone: prod
version: v1
spec:
containers:
- name: hello-ctr
image: nigelpoulton/k8sbook:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
Now we can 'docker pull' the nigelpoulton/k8sbook:latest manually, note that this docker image should exist on both DebianNode and DebianNode2:
$docker image pull nigelpoulton/k8sbook:latest
Full output of 'kubectl describe':
(00:50 dabs@CNU1343VF8 k8sbook) > kubectl describe pods hello-pod
Name: hello-pod
Namespace: default
Priority: 0
Node: debiannode/192.168.3.49
Start Time: Mon, 15 Jun 2020 00:48:01 +0800
Labels: version=v1
zone=prod
Annotations: Status: Running
IP: 10.244.1.7
IPs:
IP: 10.244.1.7
Containers:
hello-ctr:
Container ID: docker://163d9423ff5455dcac5aaeed58bbcef2f66c6a9109d11689471839250c1e6891
Image: nigelpoulton/k8sbook:latest
Image ID: docker-pullable://nigelpoulton/k8sbook@sha256:a983a96a85151320cd6ad0cd9fda3b725a743ed642e58b0597285c6bcb46c90f
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 15 Jun 2020 00:48:02 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-cqbzj (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-cqbzj:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-cqbzj
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m48s default-scheduler Successfully assigned default/hello-pod to debiannode
Normal Pulled 4m47s kubelet, debiannode Container image "nigelpoulton/k8sbook:latest" already present on machine
Normal Created 4m47s kubelet, debiannode Created container hello-ctr
Normal Started 4m47s kubelet, debiannode Started container hello-ctr
The 'spec' section(Desired State) of 'kubectl get pods -o yaml':
spec:
containers:
- image: nigelpoulton/k8sbook:latest
imagePullPolicy: IfNotPresent
name: hello-ctr
ports:
- containerPort: 8080
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-cqbzj
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: debiannode
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-cqbzj
secret:
defaultMode: 420
secretName: default-token-cqbzj
The 'status' section(Observed State) of 'kubectl get pods -o yaml':
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2020-06-14T16:48:01Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2020-06-14T16:48:02Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2020-06-14T16:48:02Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2020-06-14T16:48:01Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://163d9423ff5455dcac5aaeed58bbcef2f66c6a9109d11689471839250c1e6891
image: nigelpoulton/k8sbook:latest
imageID: docker-pullable://nigelpoulton/k8sbook@sha256:a983a96a85151320cd6ad0cd9fda3b725a743ed642e58b0597285c6bcb46c90f
lastState: {}
name: hello-ctr
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2020-06-14T16:48:02Z"
hostIP: 192.168.3.49
phase: Running
podIP: 10.244.1.7
podIPs:
- ip: 10.244.1.7
qosClass: BestEffort
startTime: "2020-06-14T16:48:01Z"