Pages - Menu

2022年8月17日 星期三

[GKE] k8s 細節補充

前言

最近幫其他組的同事看問題時,
發現有些東西是我沒看過的,
就整合再一起,寫起來當備忘拉。

正文

  1. deployment 的 lifecycle

    postStart 在container創建後,立即發送postStart事件。
    preStop 在 container結束前,立即發送preStop事件。

apiVersion: v1
kind: Pod
metadata:
  name: lifecycle-demo
spec:
  containers:
  - name: lifecycle-demo-container
    image: nginx
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
      preStop:
        exec:
          command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]

ref. 為容器的生命週期事件設置處理函數


  1. pod的終止
    通常情況下,container會發送TERM信號到每個container中,
    當超出了正常終止期限,則會向其他的processor發送KILL信號
    ref. Pod 的終止

  1. 探針
    livenessProbe :判斷container是否正常
    readinessProbe:判斷服務是否正常

  1. 查詢kubectl resouce 簡寫
kubectl api-resources

類似下列資源都可用縮寫
configmap = cm
deployment=deploy
pod = po
persistentvolumeclaims = pvc

ref .【從題目中學習k8s】-【Day8】K8s常用指令 (Cheat Sheet)&解題技巧


  1. k8s的 command ,bash -c 意思
        command: ["/bin/bash","-c"]
        args: [ "service cron start; while true; do sleep 30; done;" ]

很常看到 bash -c ,這個表示從後面的字串中 讀取命令來使用。

ps. bash 跟 sh 不一樣,sh通常是指dash。
可用下列指令,查看目前使用的shell

echo $SHELL
or
ls -l /bin/sh

ref.
- The bash shell
- 【Bash】什麼是 #!/bin/bash, #!/bin/sh,為什麼要加在 script 前面 (問題解決:sh, bash 的不同)


  1. 使用指令建立基本的 yaml
kubectl run nginx-kusc00101 --image=nginx --restart=Never --dry-run=client -o yaml> q1.pod

有基本指令後再去裡面修修改改。

如果要直接取得現有的yaml

   kubectl get deploy  yiyuan-landingpage-qa -n istio-yiyuan -o yaml > yiyuan.yaml

沒有留言:

張貼留言