K8s and Docker notes (2.1)---Hands on with Pod

(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"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值