k8s kubectl 命令用法集

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s kubectl 命令用法集相关的知识,希望对你有一定的参考价值。

KUBECTL 命令使用

kubectl 查看所有flag是否有简称

#kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
endpoints ep true Endpoints
events ev true Event
limitranges limits true LimitRange
namespaces ns false Namespace
nodes no false Node
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
pods po true Pod
podtemplates true PodTemplate
replicationcontrollers rc true ReplicationController
resourcequotas quota true ResourceQuota
secrets true Secret
serviceaccounts sa true ServiceAccount
services svc true Service
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
apiservices apiregistration.k8s.io false APIService
controllerrevisions apps true ControllerRevision
daemonsets ds apps true DaemonSet
deployments deploy apps true Deployment
replicasets rs apps true ReplicaSet
statefulsets sts apps true StatefulSet
tokenreviews authentication.k8s.io false TokenReview
localsubjectacce***eviews authorization.k8s.io true LocalSubjectAcce***eview
selfsubjectacce***eviews authorization.k8s.io false SelfSubjectAcce***eview
selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
subjectacce***eviews authorization.k8s.io false SubjectAcce***eview
horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
cronjobs cj batch true CronJob
jobs batch true Job
certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
leases coordination.k8s.io true Lease
events ev events.k8s.io true Event
daemonsets ds extensions true DaemonSet
deployments deploy extensions true Deployment
ingresses ing extensions true Ingress
networkpolicies netpol extensions true NetworkPolicy
podsecuritypolicies psp extensions false PodSecurityPolicy
replicasets rs extensions true ReplicaSet
networkpolicies netpol networking.k8s.io true NetworkPolicy
poddisruptionbudgets pdb policy true PodDisruptionBudget
podsecuritypolicies psp policy false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io false ClusterRole
rolebindings rbac.authorization.k8s.io true RoleBinding
roles rbac.authorization.k8s.io true Role
priorityclasses pc scheduling.k8s.io false PriorityClass
storageclasses sc storage.k8s.io false StorageClass
volumeattachments storage.k8s.io false VolumeAttachment

查看所有命名空间

#kubectl get ns
NAME STATUS AGE
default Active 7d23h
kube-public Active 7d23h
kube-system Active 7d23h

查看所有命名空间的pod信息

#kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-779dfc4d59-6q6ks 1/1 Running 0 3d19h
kube-system coredns-779dfc4d59-996fz 1/1 Running 0 3d19h
kube-system coredns-779dfc4d59-gs8sm 1/1 Running 0 3d20h
kube-system kubernetes-dashboard-66bddbb896-sjg92 1/1 Running 0 43h

查看某一命名空间的pod信息

#kubectl get pod -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
coredns-779dfc4d59-6q6ks 1/1 Running 0 3d19h 10.10.62.2 172.16.0.8 <none>
coredns-779dfc4d59-996fz 1/1 Running 0 3d19h 10.10.2.2 172.16.0.10 <none>
coredns-779dfc4d59-gs8sm 1/1 Running 0 3d20h 10.10.54.2 172.16.0.9 <none>
kubernetes-dashboard-66bddbb896-sjg92 1/1 Running 0 43h 10.10.62.3 172.16.0.8 <none>

查看某一命名空间的pod,svc,ep,secret信息

#kubectl get pod,svc,ep,secret -n kube-system -o wide
NAME                                        READY   STATUS    RESTARTS   AGE     IP           NODE          NOMINATED NODE
pod/coredns-779dfc4d59-6q6ks                1/1     Running   0          3d19h   10.10.62.2   172.16.0.8    <none>
pod/coredns-779dfc4d59-996fz                1/1     Running   0          3d19h   10.10.2.2    172.16.0.10   <none>
pod/coredns-779dfc4d59-gs8sm                1/1     Running   0          3d20h   10.10.54.2   172.16.0.9    <none>
pod/kubernetes-dashboard-66bddbb896-sjg92   1/1     Running   0          43h     10.10.62.3   172.16.0.8    <none>

NAME                           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE     SELECTOR
service/kube-dns               ClusterIP   169.169.0.2     <none>        53/UDP,53/TCP   3d20h   k8s-app=kube-dns
service/kubernetes-dashboard   NodePort    169.169.1.125   <none>        443:40487/TCP   43h     k8s-app=kubernetes-dashboard

NAME                                ENDPOINTS                                              AGE
endpoints/kube-controller-manager   <none>                                                 7d23h
endpoints/kube-dns                  10.10.2.2:53,10.10.54.2:53,10.10.62.2:53 + 3 more...   3d20h
endpoints/kube-scheduler            <none>                                                 7d23h
endpoints/kubernetes-dashboard      10.10.62.3:8443                                        43h

NAME                                      TYPE                                  DATA   AGE
secret/admin-token-wbjtp                  kubernetes.io/service-account-token   3      42h
secret/coredns-token-lxsg5                kubernetes.io/service-account-token   3      3d20h
secret/default-token-b4jq9                kubernetes.io/service-account-token   3      7d23h
secret/kubernetes-dashboard-certs         Opaque                                0      43h
secret/kubernetes-dashboard-key-holder    Opaque                                2      43h
secret/kubernetes-dashboard-token-tbkh5   kubernetes.io/service-account-token   3      43h

以上是关于k8s kubectl 命令用法集的主要内容,如果未能解决你的问题,请参考以下文章

k8s集群工具05:学习了解kubectl命令来使用k8s

K8s kubectl 常用命令总结,建议收藏!

k8s kubectl常用命令总结

Kubernetes(K8s) kubectl get 常用命令

k8s 读书笔记 - kubectl 命令行工具用法详解

K8S命令-Kubectl 命令大全