K8s kubectl get操作

来源:互联网 发布:怎么在淘宝买电棒 编辑:程序博客网 时间:2024/06/05 03:45

总结了一些这两天使用Kubernetes master主机上的一些操作,顺手记录下来

获取node信息

$ kubectl get nodes$ kubectl get nodes --show-labels

截取hostname行

$ kubectl describe nodes |grep kubernetes.io/hostname=$ kubectl describe nodes 10.1.235.165 |grep kubernetes.io/hostname=

给node打标签

$ kubectl label nodes {nodeName} {key=value}$ kubectl label nodes 10.1.235.165 ijk=test

删除该标签

$ kubectl label nodes {nodeName} {key-}$ kubectl label nodes 10.1.235.165 ijk-

获取yaml/json格式的详细信息

$ kubectl get namespace joetest814 -o yaml$ kubectl get node 10.1.235.165 -o json

获取deployment信息

$ kubectl get deploy --all-namespaces$ kubectl get deploy --namespace=joetest815

有待补充…

下面贴上$ kubectl get –help的说明

Display one or many resources.

Valid resource types include:

  • clusters (valid only for federation apiservers) *
    componentstatuses (aka ‘cs’) * configmaps (aka ‘cm’) *
    daemonsets (aka ‘ds’) * deployments (aka ‘deploy’) * endpoints
    (aka ‘ep’) * events (aka ‘ev’) * horizontalpodautoscalers (aka
    ‘hpa’) * ingresses (aka ‘ing’) * jobs * limitranges (aka
    ‘limits’) * namespaces (aka ‘ns’) * networkpolicies *
    nodes (aka ‘no’) * persistentvolumeclaims (aka ‘pvc’) *
    persistentvolumes (aka ‘pv’) * pods (aka ‘po’) *
    podsecuritypolicies (aka ‘psp’) * podtemplates * replicasets
    (aka ‘rs’) * replicationcontrollers (aka ‘rc’) *
    resourcequotas (aka ‘quota’) * secrets * serviceaccounts (aka
    ‘sa’) * services (aka ‘svc’) * statefulsets *
    storageclasses * thirdpartyresources

This command will hide resources that have completed. For instance,
pods that are in the Succeeded or Failed phases. You can see the full
results for any resource by providing the ‘–show-all’ flag.

By specifying the output as ‘template’ and providing a Go template as
the value of the –template flag, you can filter the attributes of the
fetched resource(s).

Examples: # List all pods in ps output format. kubectl get pods
# List all pods in ps output format with more information (such as node name). kubectl get pods -o wide
# List a single replication controller with specified NAME in ps output format. kubectl get replicationcontroller web
# List a single pod in JSON output format. kubectl get -o json pod web-pod-13je7
# List a pod identified by type and name specified in “pod.yaml” in JSON output format. kubectl get -f pod.yaml -o json
# Return only the phase value of the specified pod. kubectl get -o template pod/web-pod-13je7 –template={{.status.phase}}
# List all replication controllers and services together in ps output format. kubectl get rc,services
# List one or more resources by their type and names. kubectl get rc/web service/frontend pods/web-pod-13je7

Options:
–all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if
specified with –namespace.
–allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only
applies to golang and jsonpath output formats.
–export=false: If true, use ‘export’ for the resources. Exported resources are stripped of cluster-specific information. -f,
–filename=[]: Filename, directory, or URL to files identifying the resource to get from a server.
–include-extended-apis=true: If true, include definitions of new APIs via calls to the API server. [default true] -L,
–label-columns=[]: Accepts a comma separated list of labels that are going to be presented as columns. Names are case-sensitive. You can
also use multiple flag options like -L label1 -L label2…
–no-headers=false: When using the default or custom-column output format, don’t print headers. -o, –output=”: Output format.
One of:
json|yaml|wide|name|custom-columns=…|custom-columns-file=…|go-template=…|go-template-file=…|jsonpath=…|jsonpath-file=…
See custom columns
[http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns],
golang template [http://golang.org/pkg/text/template/#pkg-overview]
and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
–output-version=”: Output the formatted object with the given group version (for ex: ‘extensions/v1beta1’).
–raw=”: Raw URI to request from the server. Uses the transport specified by the kubeconfig file. -R, –recursive=false:
Process the directory used in -f, –filename recursively. Useful when
you want to manage related manifests organized within the same
directory. -l, –selector=”: Selector (label query) to filter on
-a, –show-all=false: When printing, show all resources (default hide terminated pods.)
–show-kind=false: If present, list the resource type for the requested object(s).
–show-labels=false: When printing, show all labels as the last column (default hide labels column)
–sort-by=”: If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath
expression (e.g. ‘{.metadata.name}’). The field in the API resource
specified by this JSONPath expression must be an integer or a string.
–template=”: Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is
golang templates [http://golang.org/pkg/text/template/#pkg-overview].
-w, –watch=false: After listing/getting the requested object, watch for changes.
–watch-only=false: Watch for changes to the requested object(s), without listing/getting first.

原创粉丝点击