亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

kubernetes 使用jq命令對資源配置查看方式

 更新時間:2022年11月30日 10:16:52   作者:我的喵叫初六  
這篇文章主要介紹了kubernetes 使用jq命令對資源配置查看方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

使用jq命令對資源配置查看

有圖形化的直接從圖形化可以看到各種資源,如Deployment、Pod等資源的配置

這里寫一個 jq 命令

jq命令允許針對json進(jìn)行操作,如過濾

jq命令centos環(huán)境下安裝

# yum -y install jq

假設(shè)我們有個文件

# cat pod-yaml
?
{
? ? "apiVersion": "v1",
? ? "kind": "Pod",
? ? "metadata": {
? ? ? ? "name": "nginx-pod",
? ? ? ? "namespace": "default"
? ? },
? ? "spec": {
? ? ? ? "containers": [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "image": "nginx:1.20",
? ? ? ? ? ? ? ? "imagePullPolicy": "IfNotPresent",
? ? ? ? ? ? ? ? "name": "nginx-pod",
? ? ? ? ? ? ? ? "resources": {
? ? ? ? ? ? ? ? ? ? "limits": {
? ? ? ? ? ? ? ? ? ? ? ? "cpu": "20m",
? ? ? ? ? ? ? ? ? ? ? ? "memory": "120Mi"
? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? "requests": {
? ? ? ? ? ? ? ? ? ? ? ? "cpu": "10m",
? ? ? ? ? ? ? ? ? ? ? ? "memory": "100Mi"
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ]
? ? }
}

我們要直接取出下面這一段

? "limits": {
? ? "cpu": "20m",
? ? "memory": "120Mi"
? },
? "requests": {
? ? "cpu": "10m",
? ? "memory": "100Mi"
? }

可以這么執(zhí)行

# cat pod-yaml | jq .spec.containers[].resources
?
輸出:
{
? "limits": {
? ? "cpu": "20m",
? ? "memory": "120Mi"
? },
? "requests": {
? ? "cpu": "10m",
? ? "memory": "100Mi"
? }
}

規(guī)律很容易看出來,就是取key的value

同樣,在查看資源時也可以這樣使用

例如查看一個pod資源限制:

查看pod名稱
# kubectl get pod
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          22s
 
 
查看該pod的資源限制
# kubectl get pod/nginx-pod -o json | jq .spec.containers[].resources
{
  "limits": {
    "cpu": "20m",
    "memory": "120Mi"
  },
  "requests": {
    "cpu": "10m",
    "memory": "100Mi"
  }
}
 
 
查看該Pod的容器重啟策略
# kubectl get pod/nginx-pod -o json | jq .spec.restartPolicy
"Always"

kubernetes常用命令總結(jié)

k8s常用命令

kubectl常用命令

創(chuàng)建資源對象

kubectl create -f xxx.yaml(文件)、kubectl create -f <directory>(目錄下所有文件)

查看資源對象

kubectl get nodes
kubectl get pods -n <namespace> -o wide

描述資源對象

kubectl describe nodes <node-name>
kubectl describe pods -n <namespace> kubectl describe <pod-name>
kubectl describe pods <rc-name>

刪除資源對象

kubectl delete -f <filename>
kubectl delete pods,services -l name=<label-name>
kubectl delete pods --all(生產(chǎn)環(huán)境慎用)

執(zhí)行容器的命令

kubectl exec <pod-name> date(默認(rèn)使用第一個容器執(zhí)行Pod的date命令)
kubectl exec <pod-name> -c <container-name> date(指定Pod中的某個容器執(zhí)行date命令)
kubectl exec -it <pod-name> -c <container-name> /bin/bash (相當(dāng)與docker exec -it <container-name> /bin/bash)

查看容器的日志

kubectl logs <pod-name>
kubectl logs -f <pod-name> -c <container-name> (相當(dāng)于tail -f 命令)

kubectl格式化輸出

顯示Pod的更多信息

kubectl get pods -n <namespace> -o wide

以yaml格式顯示

kubectl get pods -n <namespace> -o yaml

以自定義列明顯示Pod信息

kubectl get pod <pod-name> -o =custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion

基于文件的自定義列名輸出

kubectl get pods <pod-name> -o=custom-columns-file=template.txt

輸出結(jié)果排序

kubectl get pods --sort-by=.metadata.name

kubernetes集群管理指南

node的管理

命令:

kubectl replace -f xxx.yaml
kubectl patch
kubectl cordon <node_name> kubectl uncordon <node_name>(對node節(jié)點的隔離和恢復(fù))

刪除節(jié)點:

kubectl drain swarm1 --delete-local-data --force --ignore-daemonsets
kubectl delete node swarm1

使用:

kubectl get nodes
kubectl cordon <node_name> kubectl uncordon <node_name>

Label的管理:

給node設(shè)置標(biāo)簽

  • 添加:kubectl label node lustre-manager-1 node-role.kubernetes.io/minion-1=
  • 刪除:kubectl label node lustre-manager-1 node-role.kubernetes.io/minion-1-
  • 修改: kubectl label node lustre-manager-1 node-role.kubernetes.io/minion-1= --overwrite

給pod設(shè)置標(biāo)簽

把node改成pod即可

其他命令:

node節(jié)點加入master:

kubeadm join 192.168.138.131:6443 --token zlk694.ev3odwj7rbyaggz6 --discovery-token-ca-cert-hash 

sha256:eefe51ccf1c54149f5ce89423c100b1e0de8f8081c7c2c0e07a7613ef2025146

生成加入master的命令:kubeadm token create --print-join-command

刪除node節(jié)點:1)kubectl drain swarm1 --delete-local-data --force --ignore-daemonsets 2)kubectl delete node swarm1

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論