作者:半身風雪
上一節(jié):創(chuàng)建K8s集群項目
簡介:上一節(jié)我們一起學習了,如何去部署一個K8S 的應用程序,這一節(jié),我們主要講解一下,K8S 應用的框架結構。
目標
本節(jié)我將和大家一起學習Kubernetes 應用中的pod結點
- 了解 Kubernetes Pod。
- 了解 Kubernetes 工作節(jié)點。
- 對已部署的應用故障排除。
一、Kubernetes Pods
在上一節(jié)中,我們一起學會了如何使用 kubectl 創(chuàng)建一個應用。這里我們一起來重溫一遍。
- 啟動minikube 集群
minikube start
- 打開 Kubernetes 儀表板(Dashboard)
minikube dashboard
在 dashboard 中,我們找到pods 結點,并打開
1.1、Kubernetes 中的pod 是做什么的
Pod 是 Kubernetes 抽象出來的,表示一組一個或多個應用程序容器(如 Docker),以及這些容器的一些共享資源。這些資源包括:
- 共享存儲,當作卷
- 網絡,作為唯一的集群 IP 地址
- 有關每個容器如何運行的信息,例如容器映像版本或要使用的特定端口。
Pod 是為應用程序的“logic host”建模,并且可以包含相對緊耦合的不同應用容器。例如,Pod 可能既包含帶有 Node.js 應用的容器,也包含另一個不同的容器,用于提供 Node.js 網絡服務器要發(fā)布的數(shù)據(jù)。Pod 中的容器共享 IP 地址和端口,始終位于同一位置并且共同調度,并在同一工作節(jié)點上的共享上下文中運行。
Pod是 Kubernetes 平臺上的原子單元。 當我們在 Kubernetes 上創(chuàng)建 Deployment 時,該 Deployment 會在其中創(chuàng)建包含容器的 Pod (而不是直接創(chuàng)建容器)。每個 Pod 都與調度它的工作節(jié)點綁定,并保持在那里直到終止(根據(jù)重啟策略)或刪除。 如果工作節(jié)點發(fā)生故障,則會在集群中的其他可用工作節(jié)點上調度相同的 Pod。
通過運行起來的程序,我們可以在web 界面中,非常直觀的看到pods 所有信息。
二、工作結點
首先,我們先來看一張圖:
通過這張官方圖,再結合我們自己的應用程序中的pods 結點的展示內容,你是不是也發(fā)現(xiàn)了什么呢?
每一個 pod 都是運行在 工作節(jié)點中。工作節(jié)點是 Kubernetes 中的參與計算的機器,可以是虛擬機或物理計算機,具體取決于集群。每個工作節(jié)點由主節(jié)點管理。工作節(jié)點可以有多個 pod ,Kubernetes 主節(jié)點會自動處理在集群中的工作節(jié)點上調度 pod 。 主節(jié)點的自動調度考量了每個工作節(jié)點上的可用資源。
每一個 Kubernetes 工作節(jié)點必須包含Kubelet 和 容器:
- Kubelet,負責 Kubernetes 主節(jié)點和工作節(jié)點之間通信的過程; 它管理 Pod 和機器上運行的容器。
- 容器運行時(如 Docker)負責從倉庫中提取容器鏡像,解壓縮容器以及運行應用程序。
三、故障排除
我們之前一直使用的Kubectl 命令來獲取應用的相關信息,那么我們如何查看已經部署的項目的環(huán)境信息呢?當然還是使用Kubectl 相關命令咯。
3.1、常見kubectl 命令
下面我們一起來看看幾個最常見的 kubectl 命令:
- kubectl get - 列出資源
- kubectl describe - 顯示有關資源的詳細信息
- kubectl logs - 打印 pod 和其中容器的日志
- kubectl exec - 在 pod 中的容器上執(zhí)行命令
3.2、可視化界面
我們除了使用上面的 kubectl 命令 來查看及排查應用的故障之外, Kubernetes 儀表板(Dashboard)也為我們做出了最直觀的展示。
點擊應用名稱,進入詳情頁面
-
Metadata - 元數(shù)據(jù)
-
Resource information - 資源信息
- Conditions - 條件
- Controlled by - 管控器
- Persistent Volume Claims - 資源體積
- Events - 事件
- 容器狀態(tài)
四、pod 資源詳情
看到這里,肯定大家也有一些困惑,我們能不能更直觀的,查看整個pods 資源,并且做一些修改呢?下面我們一起來看一張圖:
- 查看pods 日志。
- 在pod 中重新運行編譯加載資源。
- pod 資源編輯,在這里可以修改當前pod 資源類似。
- 刪除當前pod 資源
pod 資源詳細內容文章來源:http://www.zghlxwxcb.cn/news/detail-401711.html
kind: Pod
apiVersion: v1
metadata:
name: hello-node-6b89d599b9-jdg2k
generateName: hello-node-6b89d599b9-
namespace: default
uid: 52ca897e-8cf5-469c-a221-b19d1f5f8dfc
resourceVersion: '1984'
creationTimestamp: '2022-07-01T06:36:04Z'
labels:
app: hello-node
pod-template-hash: 6b89d599b9
ownerReferences:
- apiVersion: apps/v1
kind: ReplicaSet
name: hello-node-6b89d599b9
uid: 6fff5c66-6897-47f0-b531-c7f8c6d2acb3
controller: true
blockOwnerDeletion: true
managedFields:
- manager: kube-controller-manager
operation: Update
apiVersion: v1
time: '2022-07-01T06:36:04Z'
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:generateName: {}
f:labels:
.: {}
f:app: {}
f:pod-template-hash: {}
f:ownerReferences:
.: {}
k:{"uid":"6fff5c66-6897-47f0-b531-c7f8c6d2acb3"}: {}
f:spec:
f:containers:
k:{"name":"echoserver"}:
.: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:dnsPolicy: {}
f:enableServiceLinks: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
- manager: Go-http-client
operation: Update
apiVersion: v1
time: '2022-07-01T06:36:05Z'
fieldsType: FieldsV1
fieldsV1:
f:status:
f:conditions:
k:{"type":"ContainersReady"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Initialized"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Ready"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
f:containerStatuses: {}
f:hostIP: {}
f:phase: {}
f:podIP: {}
f:podIPs:
.: {}
k:{"ip":"172.17.0.3"}:
.: {}
f:ip: {}
f:startTime: {}
subresource: status
spec:
volumes:
- name: kube-api-access-79cmb
projected:
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
name: kube-root-ca.crt
items:
- key: ca.crt
path: ca.crt
- downwardAPI:
items:
- path: namespace
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
defaultMode: 420
containers:
- name: echoserver
image: k8s.gcr.io/echoserver:1.4
resources: {}
volumeMounts:
- name: kube-api-access-79cmb
readOnly: true
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
nodeName: minikube
securityContext: {}
schedulerName: default-scheduler
tolerations:
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 300
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 300
priority: 0
enableServiceLinks: true
preemptionPolicy: PreemptLowerPriority
status:
phase: Running
conditions:
- type: Initialized
status: 'True'
lastProbeTime: null
lastTransitionTime: '2022-07-01T06:36:04Z'
- type: Ready
status: 'True'
lastProbeTime: null
lastTransitionTime: '2022-07-01T06:36:05Z'
- type: ContainersReady
status: 'True'
lastProbeTime: null
lastTransitionTime: '2022-07-01T06:36:05Z'
- type: PodScheduled
status: 'True'
lastProbeTime: null
lastTransitionTime: '2022-07-01T06:36:04Z'
hostIP: 192.168.49.2
podIP: 172.17.0.3
podIPs:
- ip: 172.17.0.3
startTime: '2022-07-01T06:36:04Z'
containerStatuses:
- name: echoserver
state:
running:
startedAt: '2022-07-01T06:36:04Z'
lastState: {}
ready: true
restartCount: 0
image: k8s.gcr.io/echoserver:1.4
imageID: >-
docker-pullable://k8s.gcr.io/echoserver@sha256:5d99aa1120524c801bc8c1a7077e8f5ec122ba16b6dda1a5d3826057f67b9bcb
containerID: >-
docker://ad3680651ec9494578d3217606d040e1ce5469eb8ba7644f8efa4d8c0d5e8411
started: true
qosClass: BestEffort
總結
本節(jié)內容相對比較簡單,但卻很重要,還是需要花費一點時間,做一個詳細的驗證學習理解的。
那么本節(jié)內容到這里就結束了,下一節(jié)我們一起學習如何將 Pod 暴露給外部實現(xiàn)通信交互。文章來源地址http://www.zghlxwxcb.cn/news/detail-401711.html
到了這里,關于【Kubernetes 系列】一文帶你吃透 K8S 應用pod結點的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!