k8s kubectl 常用命令

列出集群中可用的资源类型,可看缩写

kubectl api-resources

列出集群中可用的apiVersion

kubectl api-versions

kubectl api-versions | grep keda

查询命名空间

kubectl get ns
kubectl get namespace | grep hw

查询节点node

kubectl get node

查询节点标签

kubectl get node --show-labels

查询所有pod

kubectl get pod -A

查询指定命名空间下的pod

kubectl get pod -n project-3428

查询pod详细

kubectl -n project-3428 get pod xxxxxxxxxxxx -o wide

POD打标签

 kubectl label pod mypod app=web 

查看资源quota

> kubectl get quota -n project-12786
NAME                  AGE   REQUEST                                                                                            LIMIT
resourcequota-12786   9d    persistentvolumeclaims: 0/50, requests.cpu: 0/1, requests.memory: 0/1Gi, requests.storage: 0/3Gi   limits.cpu: 0/1, limits.memory: 0/1Gi
> kubectl get resourcequota -n project-12786
NAME                  AGE   REQUEST                                                                                            LIMIT
resourcequota-12786   9d    persistentvolumeclaims: 0/50, requests.cpu: 0/1, requests.memory: 0/1Gi, requests.storage: 0/3Gi   limits.cpu: 0/1, limits.memory: 0/1Gi

查看存储类sc

kubectl get sc

查看存储卷PV

kubectl get pv

查看存储卷声明PVC

kubectl -n project-3428 get pvc

kubectl get pv | grep project-12872

查看存储快照类

kubectl get vs -A

kubectl get volumesnapshotclass

查看存储快照

kubectl get volumesnapshot -n 命名空间

查看存储快照yaml

kubectl get volumesnapshot 具体的 -n 命名空间 -o yaml

查询指定命名空间的secret

kubectl get secret -n sc用的命名空间 

查看kubevirt虚拟机组,vmpool

kubectl -n project-3524 get virtualmachinepool

kubectl -n project-3524 get virtualmachinepool vp-100

kubectl -n project-3524 get virtualmachinepool vp-100 -o yaml

查看vm虚拟机

kubectl get vm -n project-3428

查看vmi镜像

kubectl get vmi -n project-3428

强制删除pod

kubectl delete pod newhuodai-0 --force --grace-period=0

kubectl delete -f busybox-two.yaml --force

kubectl delete pod -n default nginx-two-765d6fd96d-2csd2

查看csi驱动

> kubectl get csidriver
NAME                  ATTACHREQUIRED   PODINFOONMOUNT   STORAGECAPACITY   TOKENREQUESTS   REQUIRESREPUBLISH   MODES        AGE
cephfs.csi.ceph.com   true             false            false             <unset>         false               Persistent   14d
local.csi.com         false            false            false             <unset>         false               Persistent   14d
rbd.csi.ceph.com      true             false            false             <unset>         false               Persistent   14d

kubectl get csidrivers

查询endpoint

kubectl get endpoint -n project-3429

查询service

kubectl get svc -n 命名空间
kubectl get svc -n project-12872

kubectl get service -n project-12872

pod扩缩容

kubectl apply -f nginx.yaml
kubectl get pod -n default -o wide
kubectl get deployment -n default
# 扩容
kubectl scale deployment/nginx-100 --replicas=100 -n default

# 缩容
kubectl scale deployment/nginx-100 --replicas=1 -n default

## 查询数量
kubectl get pod -n default | grep Running | wc -l

获取configmap

kubectl get cm coredns -n kube-system -o yaml

kubectl get configmap -n project-12872

kubectl get cm -n project-12872

查看secret

kubectl get secret -n project-12872

进入pod内部

kubectl exec -it  calico-node-qz54v -n kube-system bash

查看deployment

kubectl get deployment -n csi-driver

编辑deployment

kubectl edit deployment csi-controller -n csi-driver

查看statefulset


kubectl get sts -n project-12872

kubectl get statefulset -n project-12872

查看daemonset

kubectl get daemonset -n project-12872

查看job

kubectl get job -n project-12872

创建job

kubectl create job hw-job --image=registry-dev.om:18083/service:117041 --namespace=project-12872

查看cronjob

kubectl get cronjob -n project-12872

查看hpa

kubectl get hpa -A

kubectl get hpa -n project-12872

创建cronjob资源

kubectl create cronjob hw-cronjob --schedule="*/1 * * * *" --image=registry-dev.com:18083/14756:117041 --restart=OnFailure --dry-run=client -o yaml >> hw-cronjob.yaml

注意指定namespace

查看ingress

kubectl get ingress -n project-12872

查看ingressroute

kubectl get ingressroute -n project-12872
kubectl get ingressroute -n project-12872 -o yaml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值