最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

掌握 Kubernetes 故障排除:有效維護(hù)集群的最佳實(shí)踐和工具

2023-10-23 10:30 作者:SEAL安全  | 我要投稿

Kubernetes 是一款管理容器化應(yīng)用程序的強(qiáng)大工具。然而,與任何復(fù)雜的系統(tǒng)一樣,使用它時(shí)也可能出錯(cuò)。當(dāng)問題出現(xiàn)時(shí),?

掌握有效的故障排除技術(shù)和工具非常重要

。 ? 本文將介紹以下步驟,助您了解事件收集的入門知識(shí):

檢索最新事件

使用 Pod 模擬問題

在位于 PV 的 Pod 中存儲(chǔ)事件

?

檢索最新事件

對(duì) Kubernetes 集群進(jìn)行故障診斷的第一步是檢索最新的事件。?

Kubernetes 中的事件由集群中的各種組件和對(duì)象(如 Pod、節(jié)點(diǎn)和服務(wù))生成

。它們可提供有關(guān)集群狀態(tài)和可能發(fā)生的任何問題的信息。 ? 要檢索最新事件,可以使用?Kubectl get events?命令。這將顯示集群中所有事件的列表。 kubectl get events LAST SEEN TYPE REASON OBJECT MESSAGE 78s Warning BackOff pod/bbb Back-off restarting failed container 72s Warning BackOff pod/bbb2 Back-off restarting failed container 12m Normal Pulling pod/bbb3 Pulling image

"busybox"

12m Normal Created pod/bbb3 Created container bbb3 46m Normal Started pod/bbb3 Started container bbb3 ? 如上所示,它按?

時(shí)間排序

?顯示了集群中所有通信口的列表。您還可以添加?-w?標(biāo)記,以觀察新事件發(fā)生的變化。 ? 這將顯示集群中發(fā)生事件的實(shí)時(shí)狀態(tài)。通過觀察事件,您可以?

快速識(shí)別可能發(fā)生的任何問題

。 ? 雖然?kubectl get events?命令有助于檢索事件,但如果事件按時(shí)間順序顯示,則很難識(shí)別問題。為了更容易識(shí)別問題,您可以按照?metadata.creationTimestamp?對(duì)事件進(jìn)行排序。 kubectl get events

--sort-by=.metadata.creationTimestamp

LAST SEEN

TYPE

REASON OBJECT MESSAGE

104

s Normal Pulling pod/busybox13 Pulling image

"busybox"

88

s

Warning

FailedScheduling pod/mysqldeployment-

6

f8b755598-phgzr

0

/

2

nodes are available:

2

Insufficient cpu. preemption:

0

/

2

nodes are available:

2

No preemption victims found

for

incoming pod.

104

s

Warning

BackOff pod/busybox6 Back-off restarting failed container

82

s

Warning

ProvisioningFailed persistentvolumeclaim/pv-volume storageclass.storage.k8s.io

"csi-hostpath-sc"

not

found

82

s

Warning

ProvisioningFailed persistentvolumeclaim/pv-volume-

2

storageclass.storage.k8s.io

"csi-hostpath-sc"

not

found ? 如上所示,按?metada.creationTimestamp?排序顯示集群中所有事件的列表。通過這種方式對(duì)通信口進(jìn)行排序,您可以快速識(shí)別最近的事件和可能出現(xiàn)的任何問題。 ? 使用 Pod 模擬問題

如果您發(fā)現(xiàn)存在?

與聯(lián)網(wǎng)或服務(wù)發(fā)現(xiàn)相關(guān)的問題

,?

終止

?kube-proxy?

pod

?可能會(huì)有幫助。?kube-proxy?pod 負(fù)責(zé)集群中的聯(lián)網(wǎng)和服務(wù)發(fā)現(xiàn),因此終止它有助于識(shí)別與這些功能相關(guān)的任何問題。 ? 要終止?kube-proxy?pod,可以使用?kubectl delete pod?命令。如果您需要指定?kube-proxy pod?的名稱,可以使用?kubectl get pods?命令找到它。 kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-57575c5f89-66z2h

1

/

1

Running

1

(

45h

ago)

36d

coredns-57575c5f89-bcjdn

1

/

1

Running

1

(

45h

ago)

36d

etcd-k81

1

/

1

Running

1

(

45h

ago)

36d

fluentd-elasticsearch-5fdvc

1

/

1

Running

2

(

45h

ago)

60d

fluentd-elasticsearch-wx6x9

1

/

1

Running

1

(

45h

ago)

60d

kube-apiserver-k81

1

/

1

Running

1

(

45h

ago)

36d

kube-controller-manager-k81

1

/

1

Running

2

(

45h

ago)

36d

kube-proxy-bqpb5

1

/

1

Running

1

(

45h

ago)

36d

kube-proxy-q94sk

1

/

1

Running

1

(

45h

ago)

36d

kube-scheduler-k81

1

/

1

Running

2

(

45h

ago)

36d

metrics-server-5c59ff65b6-s4kms

1

/

1

Running

2

(

45h

ago)

58d

weave-net-56pl2

2

/

2

Running

3

(

45h

ago)

61d

weave-net-rml96

2

/

2

Running

5

(

45h

ago)

62d

? 如上,將顯示 Kube 系統(tǒng)命名空間中所有 pod 的列表,其中包括?kube-proxy pod。獲得?kube-proxy pod?的名稱后,就可以使用?kubectl delete pod?命令將其刪除。 kubectl

delete

pod -n kube-

system

kube-proxy-q94sk ? 這將刪除 kube-system 命名空間中的?kube-proxy pod。Kubernetes 會(huì)自動(dòng)創(chuàng)建一個(gè)新的?kube-proxy pod?來替代它。 ? 您可以使用以下命令檢查事件: kubectl get events -n=kube-system --sort-by=.metadata.creationTimestamp LAST SEEN TYPE REASON OBJECT MESSAGE 4m59s Normal Killing pod/kube-proxy-bqpb5 Stopping container kube-proxy 4m58s Normal Scheduled pod/kube-proxy-cbkx6 Successfully assigned kube-system/kube-proxy-cbkx6 to k82 4m58s Normal SuccessfulCreate daemonset/kube-proxy Created pod: kube-proxy-cbkx6 4m57s Normal Pulled pod/kube-proxy-cbkx6 Container image

"registry.k8s.io/kube-proxy:v1.24.11"

already present on machine ? 在位于 PV 的 Pod 中存儲(chǔ)事件

將事件存儲(chǔ)在位于 PV 中的 Pod,是跟蹤 Kubernetes 集群中所發(fā)生事件的有效方法。下面是關(guān)于如何操作的分步講解: ? 為 Pod 添加權(quán)限 要在 pod 中連接 Kubernetes API,您需要賦予它適當(dāng)?shù)臋?quán)限。下面是一個(gè)將權(quán)限綁定到 pod 的 YAML 文件示例。

apiVersion:

rbac.authorization.k8s.io/v1

kind:

ClusterRoleBinding

metadata:

name:

event-logger

roleRef:

apiGroup:

rbac.authorization.k8s.io

kind:

ClusterRole

name:

cluster-admin

subjects:

-

kind:

ServiceAccount

name:

default

namespace:

default

? 創(chuàng)建持久加密卷 (PV) 和持久加密卷聲明 (PVC) 現(xiàn)在我們已經(jīng)設(shè)置好 ClusterRoleBind,可以創(chuàng)建一個(gè)持久卷來存儲(chǔ)我們的事件。下面是一個(gè)使用?hostPath?創(chuàng)建 PC 的 YAML 文件示例:

# pv.yaml

apiVersion:

v1

kind:

PersistentVolume

metadata:

name:

my-pv

spec:

capacity:

storage:

1Gi

accessModes:

-

ReadWriteOnce

hostPath:

path:

/mnt/data

---

# pvc.yaml

apiVersion:

v1

kind:

PersistentVolumeClaim

metadata:

name:

my-pvc

spec:

accessModes:

-

ReadWriteOnce

resources:

requests:

storage:

1Gi

volumeName:

my-pv

? 創(chuàng)建 Pod 以收集事件 現(xiàn)在,我們已經(jīng)設(shè)置好 PV 和 PVC,可以創(chuàng)建 Pod 來收集事件了。下面是一個(gè) YAML 文件示例,用于創(chuàng)建一個(gè) Pod,在 Pod 中連接到 Kubernetes API,并將所有事件存儲(chǔ)到文件?events.log?中。

apiVersion:

v1

kind:

Pod

metadata:

name:

event-logger

spec:

containers:

-

name:

event-logger

image:

alpine

command:

[

"/bin/sh"

,

"-c"

]

args:

-

|

apk add --no-cache curl jq && while true; do

EVENTS=$(curl -s -k -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://${KUBERNETES_SERVICE_HOST}/api/v1/events | jq -r '.items[]')

if [ -n "$EVENTS" ]; then

echo "$EVENTS" >> /pv/events.log

fi

sleep 10

done

volumeMounts:

-

name:

event-log

mountPath:

/pv

-

name:

sa-token

mountPath:

/var/run/secrets/kubernetes.io/serviceaccount

readOnly:

true

volumes:

-

name:

event-log

persistentVolumeClaim:

claimName:

my-pvc

-

name:

sa-token

projected:

sources:

-

serviceAccountToken:

path:

token

expirationSeconds:

7200

-

configMap:

name:

kube-root-ca.crt

? 該 Pod 將運(yùn)行一個(gè)安裝了?curl?和 jq 的簡(jiǎn)單 shell 腳本,使用?event-logger ClusterRoleBinding?連接到 Kubernetes API,并將所有事件存儲(chǔ)在 /pv/events.log 中。 ? 可以運(yùn)行以下命令檢查事件: kubectl

exec

event-logger --

cat

/pv/events.log ? 通過使用這些故障排除技術(shù)和工具,您可以?

保持 Kubernetes 集群的健康和平穩(wěn)運(yùn)行

。檢索最新事件、模擬問題并將事件存儲(chǔ)在位于 PV 中的 pod 中,是有效維護(hù)集群的基本步驟。隨著您對(duì) Kubernetes 的使用經(jīng)驗(yàn)越來越豐富,您可以探索更高級(jí)的工具,如用于分析事件的 Kibana、Prometheus 或 Grafana,以及集中式日志記錄解決方案,如 Elasticsearch 或 Fluentd。 ? 參考鏈接:

https://medium.com/@walissonscd/mastering-kubernetes-troubleshooting-best-practices-and-tools-for-effective-cluster-maintenance-bc1a12e7a7b2

?

掌握 Kubernetes 故障排除:有效維護(hù)集群的最佳實(shí)踐和工具的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
泌阳县| 广宗县| 柳州市| 海伦市| 武邑县| 渑池县| 汝州市| 聊城市| 宜春市| 碌曲县| 苗栗县| 广河县| 晴隆县| 贵定县| 许昌市| 如东县| 阳西县| 巩义市| 齐齐哈尔市| 辽阳县| 灵寿县| 紫阳县| 桂林市| 库车县| 广饶县| 牟定县| 莱西市| 铜鼓县| 清丰县| 罗甸县| 阜康市| 南丰县| 淮北市| 康平县| 巴青县| 白城市| 小金县| 麦盖提县| 分宜县| 法库县| 宝清县|