CKAD Note Section 8 State Persistence

105. Volumes


hostPath


這個範例 mount worker-node 的 /datapod 裡面,並且 mapping 到 container 裡面的 /test-pd
實際上我們並不會這樣做,因為 worker-node 之間的資料並沒辦法同步,一般來說會使用 shared storage 例如: NFS, ClusterFS, Ceph, AWS EBS, AzureDisk ….

CKAD Note Section 7 Service and Networking

90. Service


serivce_0

▲ NodePort type 的 service


service_type

service 的種類: NodePort, Cluster IP, LoadBlance


nodeport_0

▲ NodePort 總共有三個 port number 分別是: node-port, port, target-port


  • NodePort range: 30000~32767 (option)。
  • 如果沒有給定 targetPort,預設 port == targetPort

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
    - port: 80
      nodePort: 30007
      targetPort: 9376

NodePort service 使用 selector 來決定要將流量導向到哪些 pod 身上。
P.S 這邊先偷吃步給一個簡單的方法:
kubectl expose deployment nginx-rollout --port=80 --target-port=80

CKAD Note Section 6 Pod Design

79. Labels, Selectors and Annotations


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: v1
kind: Pod
metadata:
  name: label-demo
  labels:
    environment: production
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

我們可以在 kubernetes object 上貼上標籤 (labels) 用於分類。使用 kubectl get pod --selector <key>=<value> 可以篩選。

CKAD Note Section 5 Observability

70. Readiness and Liveness Probes


Readiness Probes

透過前面的章節我們可以得知 Pod 具有狀態 (status) 與 條件 (condition),前者顯示 lifecycle 階段 (pending, containerCreating, running)

  • pending: scheduler 正在安排 pod 到 worker-node 上,或者有問題 (kubectl describe 可以查)
  • containerCreating: pod 已經被放在 worker-node 上,正在建立容器
  • running: 執行中

Condition 的部分就有點類似細項,透過 kubectl describe 可以觀察。