日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

kubernetes?使用jq命令對資源配置查看方式_云其它

作者:我的喵叫初六 ? 更新時間: 2022-12-27 編程語言

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

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

這里寫一個 jq 命令

jq命令允許針對json進行操作,如過濾

jq命令centos環境下安裝

# yum -y install jq

假設我們有個文件

# 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"
? }

可以這么執行

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

規律很容易看出來,就是取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常用命令總結

k8s常用命令

kubectl常用命令

創建資源對象

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(生產環境慎用)

執行容器的命令

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

查看容器的日志

kubectl logs <pod-name>
kubectl logs -f <pod-name> -c <container-name> (相當于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

輸出結果排序

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節點的隔離和恢復)

刪除節點:

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設置標簽

  • 添加: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設置標簽

把node改成pod即可

其他命令:

node節點加入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節點:1)kubectl drain swarm1 --delete-local-data --force --ignore-daemonsets 2)kubectl delete node swarm1

原文鏈接:https://blog.csdn.net/weixin_38367535/article/details/123500595

欄目分類
最近更新