一.k8s资源
资源名 | 简称 | Namespaced | 资源类 |
---|
deployments | deploy | TRUE | Deployment |
ingresses | ing | TRUE | Ingress |
namespaces | ns | FALSE | Namespace |
nodes | no | FALSE | Node |
pods | po | TRUE | Pod |
replicasets | rs | TRUE | ReplicaSet |
replicationcontrollers | rc | TRUE | ReplicationController |
services | svc | TRUE | Service |
apiservices | | FALSE | APIService |
bindings | | TRUE | Binding |
certificatesigningrequests | csr | FALSE | CertificateSigningRequest |
clusterrolebindings | | FALSE | ClusterRoleBinding |
clusterroles | | FALSE | ClusterRole |
componentstatuses | cs | FALSE | ComponentStatus |
configmaps | cm | TRUE | ConfigMap |
controllerrevisions | | TRUE | ControllerRevision |
cronjobs | cj | TRUE | CronJob |
csidrivers | | FALSE | CSIDriver |
csinodes | | FALSE | CSINode |
customresourcedefinitions | crd, crds | FALSE | CustomResourceDefinition |
daemonsets | ds | TRUE | DaemonSet |
endpoints | ep | TRUE | Endpoints |
endpointslices | | TRUE | EndpointSlice |
events | ev | TRUE | Event |
horizontalpodautoscalers | hpa | TRUE | HorizontalPodAutoscaler |
jobs | | TRUE | Job |
leases | | TRUE | Lease |
limitranges | limits | TRUE | LimitRange |
localsubjectaccessreviews | | TRUE | LocalSubjectAccessReview |
mutatingwebhookconfigurations | | FALSE | MutatingWebhookConfiguration |
networkpolicies | netpol | TRUE | NetworkPolicy |
persistentvolumeclaims | pvc | TRUE | PersistentVolumeClaim |
persistentvolumes | pv | FALSE | PersistentVolume |
poddisruptionbudgets | pdb | TRUE | PodDisruptionBudget |
podsecuritypolicies | psp | FALSE | PodSecurityPolicy |
podtemplates | | TRUE | PodTemplate |
priorityclasses | pc | FALSE | PriorityClass |
resourcequotas | quota | TRUE | ResourceQuota |
rolebindings | | TRUE | RoleBinding |
roles | | TRUE | Role |
runtimeclasses | | FALSE | RuntimeClass |
secrets | | TRUE | Secret |
selfsubjectaccessreviews | | FALSE | SelfSubjectAccessReview |
selfsubjectrulesreviews | | FALSE | SelfSubjectRulesReview |
serviceaccounts | sa | TRUE | ServiceAccount |
statefulsets | sts | TRUE | StatefulSet |
storageclasses | sc | FALSE | StorageClass |
subjectaccessreviews | | FALSE | SubjectAccessReview |
tokenreviews | | FALSE | TokenReview |
validatingwebhookconfigurations | | FALSE | ValidatingWebhookConfiguration |
volumeattachments | | FALSE | VolumeAttachment |
二.k8s命令参数
1.基础命令
命令 | 描述 |
---|
create | 创建资源 |
apply | 创建或更新资源 |
expose | 创建service |
run | 运行镜像 |
get | 查询资源 |
explain | 文档参考资料 |
edit | 编辑资源 |
delete | 删除资源 |
2.扩容缩容命令
命令 | 描述 |
---|
rollout | 管理资源发布 |
rolling-update | 对控制器滚动更新 |
scale | 扩容或缩容 |
autoscale | 创建一个自动扩容缩容 |
3.集群管理命令
命令 | 描述 |
---|
certificate | 修改证书资源 |
cluster-info | 显示集群信息 |
top | 显示集群资源 |
cordon | 标记节点不可调度 |
uncordon | 标记节点可调度 |
drain | 排除节点 |
4.故障诊断命令
命令 | 描述 |
---|
describe | 显示资源的详细信息 |
logs | 打印日志 |
exec | 进入容器或者执行命令 |
cp | 拷贝文件或目录到容器 |
三.资源命令
1.get命令
kubectl get node //查看node节点
kubectl get ns //查看namespace命名空间
kubectl get pod //查看默认命名空间pod
kubectl get pod -n namespace //查看指定命名空间pod
kubectl get pod -A //查看所有命名空间pod
kubectl get pod -o wide //查看pod所在的集群ip
kubectl get node --show-labels //查看node的标签
kubectl get pod --show-labels //查看pod的标签
kubectl get svc //查看service
kubectl delete svc xxx //删除svc
kubectl get pv //查看所有pv
kubectl get pvc //查看所有pvc
kubectl get ingress //查看所有ingress
kubectl get hpa //查看所有hpa
kubectl get cm //查看所有configmap
2.describe命令
kubectl describe node //查看node节点详细信息
kubectl describe pod //查看pod详细信息
kubectl describe svc //查看svc详细信息
kubectl describe ingress //查看ingress详细信息
3.top
kubectl top node //查看node节点资源使用率
kubectl top pod //查看pod资源使用率
4.delete
kubectl delete pod xxx //删除pod
kubectl delete svc xxx //删除svc
kubectl delete ingress xxx //删除ingress
kubectl delete cm xxx //删除cm
5.label
kubectl get node --show-labels //查看node的标签
kubectl get pod --show-labels //查看pod的标签
kubectl label pod xxx version=xxx //给pod打标签,version=xxx
kubectl label node xxx version=xxx //给node打标签,version=xxx
kubectl label pod xxx version- //删除pod标签
6.rollout
kubectl rollout history xxx //查看pod历史版本
kubectl rollout undo xxx //回滚版本
7.scale,autoscale
kubectl scale deploy/nginx --replicas=3 //将nginx中的pod副本数配置为3
kubectl autoscale deployment/nginx --min=2 --max=10 //配置nginx启动自动伸缩策略,使其pod数量在2-10之间
8.cordon,uncordon,drain
kubectl cordon xxx //配置node不可调度
kubectl uncordon xxx //配置node允许调度
kubectl drain xxx //驱逐node的pod到其他节点
9.logs,exec,edit,cp
kubectl logs -f xxx //实时查看pod日志
kubectl exec -it xxx bash //进入容器
kubectl edit pod xxx //修改pod配置
kubectl cp nginx.conf xxx:/ //拷贝nginx.conf文件到xxxpod的/目录下
评论区