kubernetes實踐之五十三:Service中的故障排查

百聯達發表於2018-06-10
1.檢視某種資源的定義和用法
kubectl  explain

點選(此處)摺疊或開啟

  1. kubectl explain pod
  2. DESCRIPTION:
  3. Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.

  4. FIELDS:
  5.    apiVersion    
  6.      APIVersion defines the versioned schema of this representation of an
  7.      object. Servers should convert recognized schemas to the latest internal
  8.      value, and may reject unrecognized values. More info:
  9.      https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

  10.    kind    
  11.      Kind is a string value representing the REST resource this object
  12.      represents. Servers may infer this from the endpoint the client submits
  13.      requests to. Cannot be updated. In CamelCase. More info:
  14.      https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds

  15.    metadata    <Object>
  16.      Standard object
2.檢視Pod的狀態
kubectl get pods
kubectl describe pods my-pod
3.監控Pod狀態的變化
kubectl get pod -w
可以看到一個 namespace 中所有的 pod 的 phase 變化。
4.檢視Pod的日誌
kubectl logs my-pod
kubectl logs my-pod -c my-container
kubectl logs -f my-pod
kubectl logs -f my-pod -c my-container
5.互動式Debug
kubectl exec my-pod -it /bin/bash
kubectl top pod POD_NAME --containers
6.Pod的臨終遺言
Pod的定義中透過.spec.containers[].terminationMessagePath指定在容器中的臨終遺言日誌檔案的路徑,預設值是/dev/termination-log.這個檔案在Pod的整個生命週期內都會儲存,每次新建一個Pod,都會在宿主機上建立一個檔案,然後掛載到Pod的容器中,這些檔案不會因為容器的銷燬而丟失,所以容器可以把臨終遺言寫入這個檔案,方便問題安排排錯。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28624388/viewspace-2155913/,如需轉載,請註明出處,否則將追究法律責任。

相關文章