一句话介绍k8s常用的命令

1、资源

①查看cpu耗用: kubectl top pod_name

②查看节点或pod详细信息: kubectl describe node_name/pod_name -o wide

③查看集群节点运行状态信息: kubectl get nodes

④查看pod运行状态:kubectl get pod  pod_name

⑤提高集群pod的副本数: kubectl scale deployment webserver(deployment_name)  --replicas=6

⑥查看pod错误日志: kubectl logs pod_name| grep -i error

⑦应用编写好的资源对象yaml文件: kubectl apply -f    pod.yaml

⑧覆盖更新配置yaml文件: kubectl replace -f pod.yaml

⑨查看pod或其他资源对象文件中的参数变量: kubectl explain pods.spec.containers

⑩查看所有资源: kubectl api-resources

2、调度

①查看所在集群: kubectl config  get-contexts

②切换k8s集群: kubectl config  use-context yk8s

③设置某工作节点不可调度,并清空节点上运行的Pod:kubectl drain ynode1(节点名)  --ignore-daemonsets(不设置正在清空的节点上启动新的 Pod)

④仅设置某工作节点不可调度:kubectl cordon ynode2  

⑤去除某工作节点不可用标签:kubectl uncordon ynode1

⑥查看有污点标签的工作节点: kubectl describe node ynode1 | grep -i taints

⑦查看有disk=ssd标签的节点/pod:kubectl get nodes/pods  -l disk=ssd

3、网络

①查看ingress控制器: kubectl get  ingressclasses.networking.k8s.io

②查看某一名称空间下的ingress资源:kubectl -n my-app get ingress

③创建ingress规则资源:kubectl -n namespace_name create ingress pong(ingress_name)  --class=nginx --rule=a.com(域名) /.*=TCP(service_name):80(服务端口)  --dry-run=client  -o yaml  > ingress.yaml

④查看某一名称空间的networkpolicy:  kubectl -n myapp describe networkpolicies networkpolicy_name

⑤查看服务信息:kubectl get service service_name

4、存储

①查看持久卷信息: kubectl get  persistentvolumes persistentvolume_name

②查看持久卷申领信息: kubectl get persistentvolumeclaims  persistentvolumeclaim_name

③编辑已存在持久卷申领配置并记录:kubectl edit pvc  pvc_name  --record

5、权限(包含create、delete、deletecollection、patch(补丁范围小)、update(更新范围大)、get、list、watch(监控))

①创建具有新建 DeploymentStatefulSetDaemonSet 类型资源的权限的名为 deployment-clusterroleClusterRole 角色:   kubectl create clusterrole deployment-clusterrole --resource=deploy,sts,ds --verb=create

②在现有 namespace: app-team1 中创建一个名为 cicd-token 的新 ServiceAccount :

kubectl -n app-team1 create serviceaccount cicd-token

③仅限于 namespace: app-team1 中使用新建的角色为 cicd-token 授权:

kubectl -n app-team1 create  rolebinding rolebind-cicd-token --clusterrole=deployment-clusterrole  --serviceaccount=app-team1:cicd-token(集群授权用clusterolebinding)


                
  • 24
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值