網站首頁 編程語言 正文
使用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
相關推薦
- 2022-04-25 ASP.NET?Core中Razor頁面的Handlers處理方法詳解_基礎應用
- 2022-04-16 python用socket實現協議TCP長連接框架_python
- 2022-04-21 提升Python編碼能力的3個重要概念_python
- 2022-03-04 Tue Dec 01 00:00:00 GMT+08:00 1998 轉成自定義字符串
- 2022-02-11 git clone報RPC failed; curl 18 transfer closed with
- 2022-09-06 一文詳解Python如何優雅地對數據進行分組_python
- 2022-12-09 C語言新手練習題之求第n個斐波那契數_C 語言
- 2022-10-04 python3實現倒計時效果_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支