zh-trans: merge zh content from release-1.16-temporary into release-1.16 (#18216)

* Update http-proxy-access-api.md (#16932)

* Update coredns.md (#16930)

* zh-trans:/docs/docs/concepts/workloads/pods/ephemeral-containers.md (#16948)

* update zh-trans of define-environment-variable-container.md (#16999)

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

* update chinese docs (#16985)

* Fix ordered list (#16988)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* zh-trans:/docs/reference/setup-tools/kubeadm/kubeadm-upgrade-phase.md (#16951)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* Remove redundant symbol and fix some ordered list (#17000)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* update-zh-translation/docs/reference/setup-tools/kubeadm/kubeadm-init.md (#16997)

* update zh translation kubeadm-reset.md kubeadm-upgrade.md (#16992)

* Create kubeadm_join_phase_control-plane-join_all.md (#16987)

* Update web-ui-dashboard.md (#16976)

* update format problem (#16956)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* zh-trans:/docs/docs/concepts/storage/volume-pvc-datasource.md (#17021)

* update zh translation /docs/reference/access-authn-authz/webhook.md (#16860)

* fix confict update zh translation (#16863)

* zh-trans:/docs/concepts/workloads/pods/disruptions.md (#16983)

* zh-trans:/docs/concepts/workloads/pods/disruptions.md

* Update content/zh/docs/concepts/workloads/pods/disruptions.md

Co-Authored-By: Qiming <tengqim@cn.ibm.com>

* update zh translation content/zh/docs/reference/command-line-tools-reference/kube-scheduler.md (#17006)

* Update RC's link (#16935)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

Update

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update the style

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* Update the links for /zh/docs/setup (#16938)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* zh-trans:/docs/docs/concepts/services-networking/dual-stack.md (#17024)

* update zh translation /reference/setup-tools/kubeadm/generated/kubeadm.md (#17036)

* update zh tanslation /reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubelet_config_download.md (#17037)

* update zh translation -/reference/setup-tools/kubeadm/generated/kubeadm_alpha.md (#17038)

* update zh translation /docs/contribute/participating.md (#17040)

* Fix cri-o's links to match English docs (#16936)

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

* update zh translation content/zh/docs/reference/kubectl/jsonpath.md (#16862)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_token_generate.md (#17049)

* update Unkown ->  Unknown (#17062)

* zh-translation:high-availability.md (#16960)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* update Runnning -> Running (#17061)

* zh-trans:/docs/docs/concepts/storage/volume-snapshots.md (#17054)

* update zh transation /docs/reference/setup-tools/kubeadm/generated/kubeadm_reset.md (#17060)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_token_create.md (#17052)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_token.md (#17055)

* update zh translation update-zh-translation-/docs/reference/setup-tools/kubeadm/generated/kubeadm_token_list.md (#17048)

* update zh-translation:ha-topology.md (#17099)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* zh-trans /reference/setup-tools/kubeadm/generated/kubeadm_config_images_list.md (#17093)

* update zh translation /reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_all.md (#17083)

* Add Chinese translation for scheduler-perf-tuning (#17087)

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for scheduler-perf-tuning

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for scheduler-perf-tuning

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for scheduler-perf-tuning

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

* zh trans content/zh/docs/setup/production-environment/tools/kubeadm/control-plane-flags.md (#17121)

* update zh trans content/zh/docs/tasks/access-application-cluster/service-access-application-cluster.md (#17122)

* zh-translation:content/zh/docs/tasks/administer-cluster/namespaces-walkthrough.md (#17105)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* update-zh-translation-/docs/reference/setup-tools/kubeadm/generated/kubeadm_config_migrate.md (#17091)

* update zh trans /docs/setup/learning-environment/minikube.md (#17143)

* update zh trans /zh/docs/reference/_index.md (#17146)

* update zh trans /docs/tasks/access-application-cluster/port-forward-access-application-cluster.md (#17134)

* update zh translation 20191020-update-zh-translation-/docs/contribute/localization.md (#17046)

* update zh trans /docs/reference/using-api/client-libraries.md (#17144)

* update zh trans /docs/reference/setup-tools/kubeadm/generated/kubeadm_version.md (#17145)

* update zh /docs/reference/setup-tools/kubeadm/generated/kubeadm_upgrade_node.md (#17131)

* update zh translation /reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_front-proxy-client.md (#17081)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig.md (#17078)

* add zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-join_update-status.md (#17076)

* update zh trans content/zh/docs/contribute/generate-ref-docs/kubectl.md (#17165)

* update zh translation /reference/command-line-tools-reference/kube-proxy.md (#17107)

* zh-trans:/docs/docs/concepts/workloads/pods/pod-topology-spread-const… (#16955)

* zh-trans:/docs/docs/concepts/workloads/pods/pod-topology-spread-constraints.md

* Update pod-topology-spread-constraints.md

* zh-trans:/docs/concepts/configuration/scheduling-framework.md (#17088)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_upload-config_kubelet.md (#17079)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_control-plane_apiserver.md (#17077)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-join.md (#17075)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_token_delete.md (#17050)

* update zh trans /docs/concepts/overview/working-with-objects/namespaces.md (#17205)

* update zh trans /docs/concepts/overview/what-is-kubernetes.md (#17203)

* pr_release-1.16_crictl (#17201)

* update zh docs/tasks/administer-cluster/dns-debugging-resolution.md (#17186)

* update zh trans content/zh/docs/concepts/overview/working-with-objects/field-selectors.md (#17191)

* translate configure_upgrade_etcd (#17160)

* translate kubeadm_upgrade_apply (#17159)

* update zh /docs/tasks/job/coarse-parallel-processing-work-queue.md (#17155)

* translate docs/setup/release/version-skew-policy.md to Chinese (#17142)

* update zh trans content/zh/docs/tasks/access-application-cluster/create-external-load-balancer.md (#17124)

* zh-trans replace the wrong translation (#17103)

zh-trans replace the wrong translation

* Merged 1.14~1.16 changes (#17117)

* zh-trans:/docs/concepts/configuration/assign-pod-node.md (#17129)

* update zh trans /docs/contribute/generate-ref-docs/kubernetes-api.md (#17161)

* pr_release-1.16_basic-ss (#17169)

* Add zh-trans of assign-cpu-resource.md (#17063)

Signed-off-by: heqg <he.qingguo@zte.com.cn>

Add zh-trans of assign-cpu-resource.md

Signed-off-by: heqg <he.qingguo@zte.com.cn>

Add zh-trans of assign-cpu-resource.md

Signed-off-by: heqg <he.qingguo@zte.com.cn>

Add zh-trans of assign-cpu-resource.md

Signed-off-by: heqg <he.qingguo@zte.com.cn>

Add zh-trans of assign-cpu-resource.md

Signed-off-by: heqg <he.qingguo@zte.com.cn>

* update zh trans content/zh/docs/concepts/overview/working-with-objects/common-labels.md (#17193)

* update zh translation /docs/contribute/intermediate.md (#17041)

* zh-trans:docs/setup/production-environment/turnkey/tencent.md (#17207)

* pr_release-1.16_mysql-wordpress-pv (#17202)

* pr_release-1.16_reconfig-kubelet (#17200)

* zh-trans:/docs/docs/concepts/workloads/controllers/jobs-run-completio… (#17020)

* zh-trans:/docs/docs/concepts/workloads/controllers/jobs-run-completion.md

* Update jobs-run-completion.md

* Update jobs-run-completion.md

* update zh trans content/zh/docs/concepts/extend-kubernetes/extend-cluster.md (#17212)

* update zh trans content/zh/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation.md (#17213)

* add zh trans /docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-prepare_kubeconfig.md (#17220)

kubeadm_join_phase_control-plane-prepare_download-certs.md

* add zh trans /reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs.md and /reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-prepare.md (#17219)

* update zh trans content/zh/docs/concepts/containers/images.md (#17216)

* ZH-trans: add _index.md (#17214)

* ZH-trans: add _index.md

* add _index.md file

* add _index.md files

* pr_release-1.16_crd-versions (#17198)

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_config_images_pull.md (#17092)

* zh-trans /reference/setup-tools/kubeadm/generated/kubeadm_config_images.md (#17094)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_addon_kube-proxy.md   and   content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_sa.md (#17222)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-prepare_all.md  content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-prepare_certs.md (#17221)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_addon_all.md (#17223)

* 013 /docs/concepts/services networking/ingress.md (#17185)

* x

* update zh trans content/zh/docs/concepts/services-networking/ingress.md

* zh-trans:/reference/setup-tools/kubeadm/generated/kubeadm_completion.md and kubeadm_config.md (#17097)

* add zh trans reference/glossary/pod-lifecycle (#17226)

* update zh-translation document (#17096)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* update zh-translation:setup-ha-etcd-with-kubeadm.md (#17098)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* add zh trans /docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_selfhosting.md and /docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubelet_config_enable-dynamic.md (#17227)

* add zh trans /docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubeconfig_user.md and /docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_upload-config_kubeadm.md (#17228)

* zh-translation:content/zh/docs/tasks/extend-kubectl/kubectl-plugins.md (#17089)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* update zh translation /docs/reference/setup-tools/kubeadm/generated/kubeadm_join.md (#17080)

* update zh translation /reference/setup-tools/kubeadm/generated/kubeadm_config_view.md (#17085)

* zh-translation:troubleshooting-kubeadm.md (#17069)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* zh-trans: docs/concepts/scheduling/kube-scheduler.md (#17067)

* Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

Add Chinese translation for kube-scheduler

Signed-off-by: GeorgeSen <wang.sen2@zte.com.cn>

* Update kube-scheduler.md

* Add Chinese translation for kube-scheduler

* Update kube-scheduler.md

* Update kube-scheduler.md

* Update kube-scheduler.md

* translate pods.md  and init-containers.md for branch release-1.16 (#17208)

* update zh translation /docs/contribute/start.md (#17039)

* zh-translation:2017-10-00-Five-Days-Of-Kubernetes-18.md (#17229)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* translate kubeadm-certs.md (#17090)

* update the Illegal comment such as : (<!--、<--) (#17266)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_etcd-ca.md (#17268)

* update zh /docs/concepts/architecture/cloud-controller.md (#17263)

* update zh /docs/concepts/cluster-administration/logging.md (#17247)

* modify the show of zh translation /concepts/overview/what-is-kubernetes.md /reference/setup-tools/kubeadm/generated/kubeadm_init.md  /reference/setup-tools/kubeadm/kubeadm-init.md (#17246)

* zh-translation:kubeadm_init_phase_control-plane_all.md (#17243)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* zh-translation:kubeadm_join_phase_control-plane-join_etcd.md (#17236)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubelet-start.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_upload-certs.md (#17230)

* add content/zh/docs/reference/glossary/container-runtime.md file fix-up to pass the ci and trans content/zh/docs/reference/glossary/container-runtime.md、content/zh/docs/concepts/overview/components.md (#17211)

* zh-translation:mirror-pod.md (#17231)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* zh-translation:kubeadm_init_phase_upload-config.md (#17238)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* update zh /docs/concepts/workloads/pods/pod-overview.md (#17239)

* update the format of zh translation content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_reset.md content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_upgrade.md   content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_upgrade_apply.md  content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_upgrade_plan.md  content/zh/docs/reference/setup-tools/kubeadm/kubeadm-config.md  content/zh/docs/reference/setup-tools/kubeadm/kubeadm-reset.md  content/zh/docs/reference/setup-tools/kubeadm/kubeadm-token.md  content/zh/docs/reference/setup-tools/kubeadm/kubeadm-upgrade.md (#17248)

* Create advanced.md (#17256)

* Create advanced.md

* trans the advanced.md and fix the build bugs

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_control-plane.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_control-plane_scheduler.md (#17269)

* zh-translation:kubelet-integration.md (#17272)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* pr_release-1.16_out-of-resource (#17199)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_front-proxy-ca.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_control-plane_controller-manager.md (#17267)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_etcd-peer.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig_admin.md (#17271)

* pr_release-1.16_ext-admission-ctl (#17196)

* update zh translation /docs/contribute/advanced.md (#17042)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_apiserver-etcd-client.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_ca.md (#17275)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_config_print.md update zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_config.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_config_print_init-defaults.md (#17282)

* add zh trans  content/zh/docs/reference/setup-tools/kubeadm/generated… (#17287)

* add zh trans  content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_etcd.md content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_upload-config_all.md update zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_control-plane.md

* Update kubeadm_init_phase_etcd.md

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/… (#17285)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_etcd-server.md content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubelet.md update zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_apiserver.md

* Update kubeadm_alpha_kubelet.md

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_all.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_addon.md fix-up bad comment kubeadm_alpha_certs_renew.md、kubeadm_alpha_certs_renew_apiserver-etcd-client.md、kubeadm_init_phase_addon_all.md (#17276)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/… (#17281)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_etcd_local.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_config_print_join-defaults.md

* Update kubeadm_init_phase_etcd_local.md

* zh trans update-daemon-set.md (#16872)

* zh trans update-daemon-set.md

* Update update-daemon-set.md

* managing-tls-in-a-cluster.md (#16874)

* update-api-object-kubectl-patch.md (#16875)

* improve the zh trans /kubeadm/generated/kubeadm_init_phase_.* 1 (#17295)

* improve the zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_config_.* (#17294)

* modify the zh translation content/zh/docs/reference/setup-tools/kubea… (#17293)

* modify the zh translation content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_.*

* Update kubeadm_alpha.md

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig_all.md and content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_preflight.md (#17280)

* add zh /docs/reference/glossary/cgroup.md (#17291)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubelet_config.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_apiserver-kubelet-client.md (#17288)

* improve zh trans of command in /kubeadm/generated/kubeadm_init_phase_.* files (#17297)

* improve zh command translation /kubeadm/generated/kubeadm_init_.* files (#17298)

* update zh trans in /kubeadm/generated/kubeadm_.* files (#17306)

* add zh trans /reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_etcd-healthcheck-client.md、/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_etcd-peer.md、/reference/setup-tools/kubeadm/generated/kubeadm_alpha_kubeconfig.md (#17308)

* Improve previously translated documents (#17327)

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* zh-trans: docs/setup/production-environment/turnkey/aws.md (#17320)

* Update zh.toml

* update zh trans /generated/kubeadm_join_phase_.* files (#17301)

* Update zh.toml

* add zh /docs/reference/glossary/pod-disruption-budget.md (#17344)

* pr_release-1.16_config-aggregation-layer (#17197)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_controller-manager.conf.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_scheduler.conf.md (#17390)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig_scheduler.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-prepare_control-plane.md (#17381)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_apiserver-kubelet-client.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_control-plane-join_mark-control-plane.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_kubelet-start.md (#17380)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_addon_coredns.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_bootstrap-token.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_apiserver.md (#17383)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_certificate-key.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_reset_phase_preflight.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_reset_phase_update-cluster-status.md (#17385)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_admin.conf.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_reset_phase.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_reset_phase_cleanup-node.md (#17387)

* add zh trans content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_apiserver-kubelet-client.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_certs_renew_front-proxy-client.md、content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_alpha_selfhosting_pivot.md (#17384)

* add zh /docs/reference/glossary/limitrange.md (#17324)

* add zh trans content/zh/docs/setup/best-practices/cluster-large.md (#17321)

* add zh trans content/zh/docs/setup/best-practices/cluster-large.md

* Update cluster-large.md

* add zh trans /docs/reference/setup-tools/kubeadm/kubeadm-alpha.md、/do… (#17403)

* add zh trans /docs/reference/setup-tools/kubeadm/kubeadm-alpha.md、/docs/reference/setup-tools/kubeadm/generated/kubeadm_join_phase_preflight.md、/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_certs_etcd-server.md

* Update kubeadm_init_phase_certs_etcd-server.md

* add zh /docs/reference/glossary/cluster-operations.md (#17300)

* add zh /docs/reference/glossary/applications.md (#17419)

* update zh trans kubelet (#17379)

* update zh trans kubelet

* update the file according to feedback from reviewer tengqm

* update 1000-1757 lines

* update the advice zh trans

* add zh /docs/reference/glossary/static-pod.md (#17418)

* add zh /docs/reference/glossary/preemption.md (#17423)

* add zh /docs/reference/glossary/pod-priority.md (#17421)

* add zh /docs/reference/glossary/control-plane.md (#17425)

* add zh /docs/reference/glossary/cluster-infrastructure.md (#17424)

* pr_release-1.16_api-overview (#17444)

* pr_release-1.16_daemonset (#17435)

* pr_release-1.16_gc (#17445)

* pr_release-1.16_qos-class (#17442)

* fix QoS Class to QoS 类 (#17464)

* pr_release-1.16-abac (#17427)

* zh-trans:docs/setup/production-environment/turnkey/alibaba-cloud.md (#17345)

* pr_release-1.16_endpoint-slice (#17468)

* pr_release-1.16_taint (#17469)

* pr_release-1.16_operator-pattern (#17467)

* pr_release-1.16_ss (#17433)

* pr_release-1.16_admission-controller (#17440)

* pr_release-1.16_containerd (#17441)

* pr_release-1.16_app-container (#17466)

* add zh-trans content/zh/docs/setup/_index.md、content/zh/docs/setup/release/_index.md (#17503)

* pr-release-1.16_enabling-endpoint-slices (#17504)

* update zh trans content/zh/docs/reference/setup-tools/kubeadm/kubeadm… (#17495)

* update zh trans content/zh/docs/reference/setup-tools/kubeadm/kubeadm-upgrade-phase.md、content/zh/docs/reference/setup-tools/kubeadm/kubeadm-init-phase.md

* add content/zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig_kubelet.md

* pr-release-1.16_logging (#17491)

* pr-release-1.16_cri (#17486)

* add zh-trans:docs/setup/production-environment/turnkey/azure.md (#17482)

* pattern translate into 模式 (#17485)

* fix zk affinity description in zh trans (#17393)

* pr-release-1.16_ephemeral-container (#17487)

* pr-release-1.16_data-plane (#17489)

* pr-release-1.16_cncf (#17490)

* zh-trans add content\zh\docs\tools\install-minikube.md (#16920)

* zh-trans add content\zh\docs\tools\install-minikube.md

* zh-trans update content\zh\docs\tools\install-minikube.md

* zh-trans update content\zh\docs\tools\install-minikube.md

* update \docs\tasks\tools\install-minikube.md

* update docs\concepts\workloads\controllers\deployment.md

* update deployment.md

* pr-release-1.16_extensions (#17492)

* pr-release-1.16_toleration (#17493)

* Revert "update zh trans content/zh/docs/reference/setup-tools/kubeadm/kubeadm… (#17495)" (#17521)

This reverts commit 1134c14e0a39bdc3d1a920ac9797139a6dcccf4b.

* motidy extensions in content/zh/docs/reference/glossary/extensions (#17524)

* motidy toleration in content/zh/docs/reference/glossary/toleration.md (#17523)

* motidy toleration in content/zh/docs/reference/glossary/toleration.md

* Update toleration.md

* improve zh-trans in content/zh/docs/setup/_index.md (#17526)

* add zh-trans /zh/docs/reference/setup-tools/kubeadm/generated/kubeadm_init_phase_kubeconfig_kubelet.md (#17527)

* Broken Link (#17546)

Issue available at https://kubernetes.io/zh/docs/concepts/containers/runtime-class/
and introduced by original English documentation (see #17543)

* Update trans kubeadm_upgrade_plan.md (#17395)

* Update kubeadm_upgrade_plan.md

* Update kubeadm_upgrade_plan.md

* Update kubeadm_upgrade_plan.md

* Update kubeadm_upgrade_plan.md

* Update kubeadm_upgrade_plan.md

* Update kubeadm_upgrade_plan.md

* update zh-trans of define-command-argument-container.md (#17022)

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

update zh-trans of define-command-argument-container.md

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

Add back the Original English

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

update title of define-command-argument-container.md

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

update table title and reference

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

update reference of define-command-argument-container.md

Signed-off-by: Yixiang2019 <wang.yixiang@zte.com.cn>

* ZH-trans: fix multiple jump links and update files (#17603)

* ZH-trans: fix multiple jump links and update files

* Update _index.html

* update zh trans content/zh/docs/reference/setup-tools/kubeadm/kubeadm-init-phase.md (#17528)

* update zh trans /doc/concepts/architecture/nodes.md (#17617)

* update zh trans content/zh/docs/concepts/architecture/nodes.md

* fix-up content/zh/docs/concepts/architecture/nodes.md

* add zh-trans /docs/setup/release/notes.md (#17519)

* add zh-trans /docs/setup/release/notes.md

update-750

*  fix-up 1575 line and udpate 2483 line

* update to line 2980

* update to the last line 3160

* add zh-trans:docs/setup/production-environment/turnkey/icp.md (#17568)

* zh-trans: /docs/setup/production-environment/container-runtimes.md (#17646)

* zh-trs:container-runtimes.md

Signed-off-by: yuxiaobo <yuxiaobogo@163.com>

* Update container-runtimes.md

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md into Chinese (#17791)

* Translate /docs/concepts/cluster-administration/cloud-providers.md into Chinese

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md into Chinese

* Sorry, wrong commit, roll back...

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md into Chinese

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md into Chinese

* Create trans kubeadm_upgrade_diff.md (#17392)

* Update kubeadm_upgrade_diff.md

* Update kubeadm_upgrade_diff.md

* Update kubeadm_upgrade_diff.md

* Create _index.md (#17831)

* zh-trans zh-trans-/docs/reference/command-line-tools-reference/feature-gates.md (#17658)

* Update volume-snapshots.md (#17829)

* Update volume-snapshots.md

* Update volume-snapshots.md

* Update volume-snapshots.md

* Create ovirt.md (#17849)

* Create ovirt.md

* Update ovirt.md

* Translate /docs/concepts/cluster-administration/cloud-providers.md into Chinese (#17761)

* Translate /docs/concepts/cluster-administration/cloud-providers.md into Chinese

* Translate /docs/concepts/workloads/controllers/ttlafterfinished.md into Chinese

* Sorry, wrong commit, roll back...

* Update translation after tengqm's review.

* Update cloud-providers.md

* Update dual-stack.md (#17836)

* Update dual-stack.md

* Update dual-stack.md

* Update dual-stack.md

* Update dual-stack.md

* Create validate-dual-stack.md (#17833)

* Create validate-dual-stack.md

* Update validate-dual-stack.md

* translation content/zh/docs/reference/setup-tools/kubeadm/ kubeadm-join-phase、kubeadm-reset-phase (#17881)

* zh-trans content/zh/docs/contribute/generate-ref-docs/contribute-upstream.md (#17882)

* Chinese translation /docs/tasks/administer-cluster/highly-available-master.md (#17884)

* Chinese translation /docs/tasks/administer-cluster/highly-available-master.md

* Apply suggestions from code review

Co-Authored-By: Qiming <tengqim@cn.ibm.com>

* Fix format issue (#17921)

* Create topology-manager.md (#17901)

* Create topology-manager.md

* Update topology-manager.md

* add zh-trans:docs/setup/production-environment/windows/user-guide-windows-containers.md (#17876)

* Update pod-overhead.md (#17931)

* Update scheduler-perf-tuning.md (#17934)

* Create dcos.md (#17932)

* Create dcos.md

* Update dcos.md

* Update object-management.md (#17937)

* zh-translation content/zh/docs/setup/production-environment/tools/kops.md (#17991)

* Create imperative-config.md (#17956)

* Create imperative-config.md

* Update imperative-config.md

* Create self-hosting.md (#17950)

* Create resource-bin-packing.md (#17935)

* Create nodelocaldns.md (#17938)

* Update config.toml(release-1.16) for 1.17 (#18025)

* Update config.toml(release-1.16) for 1.17

* Update config.toml

* Remove ru language

* fix shotcode mismatch

Co-authored-by: zhangx501 <zhang0000xun@gmail.com>
Co-authored-by: ZhongliangXiong <xiong.zhongliang@zte.com.cn>
Co-authored-by: Yixiang Wang <wang.yixiang@zte.com.cn>
Co-authored-by: li mengyang <hwdef97@gmail.com>
Co-authored-by: PingWang <wang.ping5@zte.com.cn>
Co-authored-by: chentanjun <tanjunchen20@gmail.com>
Co-authored-by: Sophy417 <53026875+Sophy417@users.noreply.github.com>
Co-authored-by: Qiming <tengqim@cn.ibm.com>
Co-authored-by: yuxiaobo96 <41496192+yuxiaobo96@users.noreply.github.com>
Co-authored-by: senwang <wang.sen2@zte.com.cn>
Co-authored-by: lichuqiang <lichuqiang@huawei.com>
Co-authored-by: lpf7551321 <liupengfei20@huawei.com>
Co-authored-by: Hongcai Ren <renhongcai@huawei.com>
Co-authored-by: jiajie <jiaj12@chinaunicom.cn>
Co-authored-by: heqg <56527988+heqg@users.noreply.github.com>
Co-authored-by: IreneByron <zhangbingqing7@huawei.com>
Co-authored-by: LiuDui <1693291525@qq.com>
Co-authored-by: Wang Bing <wangbing.adam@gmail.com>
Co-authored-by: Damini Satya <daminisatya@gmail.com>
Co-authored-by: liufangwai <liufangwai@huawei.com>
Co-authored-by: wangcong <congfairy2536@gmail.com>
Co-authored-by: XuefeiWang2 <wangxuefei2@huawei.com>
Co-authored-by: Kubernetes Prow Robot <k8s-ci-robot@users.noreply.github.com>
Co-authored-by: Ziqiu Zhu <zzqshu@126.com>
Co-authored-by: ten2ton <50288981+ten2ton@users.noreply.github.com>
Co-authored-by: Oleg Butuzov <butuzov@users.noreply.github.com>
Co-authored-by: jiazxjason <52809535+jiazxjason@users.noreply.github.com>
Co-authored-by: Coffey Gao <coffiney@qq.com>
Co-authored-by: Bingshen Wang <bingshen.wbs@alibaba-inc.com>
This commit is contained in:
SataQiu
2019-12-25 08:53:29 +08:00
committed by Kubernetes Prow Robot
parent 6be3e1414d
commit 0f2bd2871b
932 changed files with 113356 additions and 8088 deletions
+7 -1
View File
@@ -1,5 +1,11 @@
---
title: "kubectl 命令行界面"
weight: 60
---
<!--
---
title: "kubectl CLI"
weight: 60
---
-->
@@ -0,0 +1,679 @@
---
title: kubectl 备忘单
reviewers:
- erictune
- krousey
- clove
content_template: templates/concept
card:
name: reference
weight: 30
---
<!-- ---
title: kubectl Cheat Sheet
reviewers:
- erictune
- krousey
- clove
content_template: templates/concept
card:
name: reference
weight: 30
--- -->
{{% capture overview %}}
<!-- See also: [Kubectl Overview](/docs/reference/kubectl/overview/) and [JsonPath Guide](/docs/reference/kubectl/jsonpath). -->
也可以看下: [Kubectl 概述](/docs/reference/kubectl/overview/) 和 [JsonPath 指南](/docs/reference/kubectl/jsonpath)。
<!-- This page is an overview of the `kubectl` command. -->
本页面是 `kubectl` 命令的概述。
{{% /capture %}}
{{% capture body %}}
<!-- # kubectl - Cheat Sheet -->
## kubectl - 备忘单
<!-- ## Kubectl Autocomplete -->
## Kubectl 自动补全
### BASH
<!-- ```bash
source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
``` -->
```bash
source <(kubectl completion bash) # 在 bash 中设置当前 shell 的自动补全,要先安装 bash-completion 包。
echo "source <(kubectl completion bash)" >> ~/.bashrc # 在您的 bash shell 中永久的添加自动补全
```
<!-- You can also use a shorthand alias for `kubectl` that also works with completion: -->
您还可以为 `kubectl` 使用一个速记别名,该别名也可以与 completion 一起使用:
```bash
alias k=kubectl
complete -F __start_kubectl k
```
### ZSH
<!-- ```bash
source <(kubectl completion zsh) # setup autocomplete in zsh into the current shell
echo "if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi" >> ~/.zshrc # add autocomplete permanently to your zsh shell
``` -->
```bash
source <(kubectl completion zsh) # 在 zsh 中设置当前 shell 的自动补全
echo "if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi" >> ~/.zshrc # 在您的 zsh shell 中永久的添加自动补全
```
<!-- ## Kubectl Context and Configuration
Set which Kubernetes cluster `kubectl` communicates with and modifies configuration
information. See [Authenticating Across Clusters with kubeconfig](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) documentation for
detailed config file information. -->
## Kubectl 上下文和配置
设置 `kubectl` 与哪个 Kubernetes 集群进行通信并修改配置信息。查看 [使用 kubeconfig 跨集群授权访问](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) 文档获取详情配置文件信息。
<!-- ```bash
kubectl config view # Show Merged kubeconfig settings.
# use multiple kubeconfig files at the same time and view merged config
KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
kubectl config view
# get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
kubectl config view -o jsonpath='{.users[].name}' # get a list of users
kubectl config get-contexts # display list of contexts
kubectl config current-context # display the current-context
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
# add a new cluster to your kubeconf that supports basic auth
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
# permanently save the namespace for all subsequent kubectl commands in that context.
kubectl config set-context --current --namespace=ggckad-s2
# set a context utilizing a specific username and namespace.
kubectl config set-context gce --user=cluster-admin --namespace=foo \
&& kubectl config use-context gce
kubectl config unset users.foo # delete user foo
``` -->
```bash
kubectl config view # 显示合并的 kubeconfig 配置。
# 同时使用多个 kubeconfig 文件并查看合并的配置
KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view
# 获取 e2e 用户的密码
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
kubectl config current-context # 展示当前所处的上下文
kubectl config use-context my-cluster-name # 设置默认的上下文为 my-cluster-name
# 添加新的集群配置到 kubeconf 中,使用 basic auth 进行鉴权
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
# 使用特定的用户名和命名空间设置上下文。
kubectl config set-context gce --user=cluster-admin --namespace=foo \
&& kubectl config use-context gce
```
<!-- ## Apply
`apply` manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running `kubectl apply`. This is the recommended way of managing Kubernetes applications on production. See [Kubectl Book](https://kubectl.docs.kubernetes.io). -->
## Apply
`apply` 通过定义 Kubernetes 资源的文件管理应用程序。它通过运行 `kubectl apply` 在集群中创建和更新资源。这是在生产中管理 Kubernetes 应用程序的推荐方法。查阅 [Kubectl 文档](https://kubectl.docs.kubernetes.io)。
<!-- ## Creating Objects -->
## 创建对象
<!-- Kubernetes manifests can be defined in json or yaml. The file extension `.yaml`,
`.yml`, and `.json` can be used. -->
Kubernetes 配置可以用 json 或 yaml 定义。可以使用的文件扩展名有 `.yaml``.yml` 和 `.json`。
<!-- ```bash
kubectl apply -f ./my-manifest.yaml # create resource(s)
kubectl apply -f ./my1.yaml -f ./my2.yaml # create from multiple files
kubectl apply -f ./dir # create resource(s) in all manifest files in dir
kubectl apply -f https://git.io/vPieo # create resource(s) from url
kubectl create deployment nginx --image=nginx # start a single instance of nginx
kubectl explain pods,svc # get the documentation for pod and svc manifests
# Create multiple YAML objects from stdin
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000000"
---
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep-less
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000"
EOF
# Create a secret with several keys
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
password: $(echo -n "s33msi4" | base64 -w0)
username: $(echo -n "jane" | base64 -w0)
EOF
``` -->
```bash
kubectl apply -f ./my-manifest.yaml # 创建资源
kubectl apply -f ./my1.yaml -f ./my2.yaml # 使用多个文件创建
kubectl apply -f ./dir # 从目录下的全部配置文件创建资源
kubectl apply -f https://git.io/vPieo # 从 url 中创建资源
kubectl create deployment nginx --image=nginx # 启动单实例 nginx
kubectl explain pods,svc # 获取 pod,svc 配置的文档说明
# 从标准输入中的多个 YAML 对象中创建
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000000"
---
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep-less
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000"
EOF
# 创建有多个 key 的 Secret
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
password: $(echo -n "s33msi4" | base64 -w0)
username: $(echo -n "jane" | base64 -w0)
EOF
```
<!-- ## Viewing, Finding Resources -->
## 获取和查找资源
<!-- ```bash
# Get commands with basic output
kubectl get services # List all services in the namespace
kubectl get pods --all-namespaces # List all pods in all namespaces
kubectl get pods -o wide # List all pods in the namespace, with more details
kubectl get deployment my-dep # List a particular deployment
kubectl get pods --include-uninitialized # List all pods in the namespace, including uninitialized ones
kubectl get pod my-pod -o yaml # Get a pod's YAML
kubectl get pod my-pod -o yaml --export # Get a pod's YAML without cluster specific information
# Describe commands with verbose output
kubectl describe nodes my-node
kubectl describe pods my-pod
kubectl get services --sort-by=.metadata.name # List Services Sorted by Name
# List pods Sorted by Restart Count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
# List pods in test namespace sorted by capacity
kubectl get pods -n test --sort-by=.spec.capacity.storage
# Get the version label of all pods with label app=cassandra
kubectl get pods --selector=app=cassandra -o \
jsonpath='{.items[*].metadata.labels.version}'
# Get all worker nodes (use a selector to exclude results that have a label
# named 'node-role.kubernetes.io/master')
kubectl get node --selector='!node-role.kubernetes.io/master'
# Get all running pods in the namespace
kubectl get pods --field-selector=status.phase=Running
# Get ExternalIPs of all nodes
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
# List Names of Pods that belong to Particular RC
# "jq" command useful for transformations that are too complex for jsonpath, it can be found at https://stedolan.github.io/jq/
sel=${$(kubectl get rc my-rc --output=json | jq -j '.spec.selector | to_entries | .[] | "\(.key)=\(.value),"')%?}
echo $(kubectl get pods --selector=$sel --output=jsonpath={.items..metadata.name})
# Show labels for all pods (or any other Kubernetes object that supports labelling)
# Also uses "jq"
for item in $( kubectl get pod --output=name); do printf "Labels for %s\n" "$item" | grep --color -E '[^/]+$' && kubectl get "$item" --output=json | jq -r -S '.metadata.labels | to_entries | .[] | " \(.key)=\(.value)"' 2>/dev/null; printf "\n"; done
# Or this command can be used as well to get all the labels associated with pods
kubectl get pods --show-labels
# Check which nodes are ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \
&& kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"
# List all Secrets currently in use by a pod
kubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq
# List Events sorted by timestamp
kubectl get events --sort-by=.metadata.creationTimestamp
``` -->
```bash
# 使用 get 命令获取基本输出
kubectl get services # 列出当前命名空间下的所有 services
kubectl get pods --all-namespaces # 列出所有命名空间下的全部的 pods
kubectl get pods -o wide # 列出当前命名空间下的全部 pods,有更多的详细信息
kubectl get deployment my-dep # 列出某个特定的 deployment
kubectl get pods --include-uninitialized # 列出当前命名空间下的全部 pods,包含未初始化的
kubectl get pod my-pod -o yaml # 获取一个 pod 的 YAML
kubectl get pod my-pod -o yaml --export # 获取一个没有集群特定信息的 YAML
# 使用 describe 命令获取详细输出
kubectl describe nodes my-node
kubectl describe pods my-pod
kubectl get services --sort-by=.metadata.name # 列出当前命名空间下所有 services,按照名称排序
# 列出 pods 按照重启次数进行排序
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
# 列出测试命名空间中的 Pod,按容量排序
kubectl get pods -n test --sort-by=.spec.capacity.storage
# 获取包含 app=cassandra 标签全部 pods 的 version 标签
kubectl get pods --selector=app=cassandra -o \
jsonpath='{.items[*].metadata.labels.version}'
# 获取所有工作节点(使用选择器以排除标签名称为 'node-role.kubernetes.io/master' 的结果)
kubectl get node --selector='!node-role.kubernetes.io/master'
# 获取当前命名空间中正在运行的 pods
kubectl get pods --field-selector=status.phase=Running
# 获取全部 node 的 ExternalIP 地址
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
# 列出属于某个特定 RC 的 pods 的名称
# "jq" 命令对于 jsonpath 过于复杂的转换非常有用,可以在 https://stedolan.github.io/jq/ 找到它。
sel=${$(kubectl get rc my-rc --output=json | jq -j '.spec.selector | to_entries | .[] | "\(.key)=\(.value),"')%?}
echo $(kubectl get pods --selector=$sel --output=jsonpath={.items..metadata.name})
# 显示所有 Pod 的标签(或任何其他支持标签的 Kubernetes 对象)
# 也可以使用 "jq"
for item in $( kubectl get pod --output=name); do printf "Labels for %s\n" "$item" | grep --color -E '[^/]+$' && kubectl get "$item" --output=json | jq -r -S '.metadata.labels | to_entries | .[] | " \(.key)=\(.value)"' 2>/dev/null; printf "\n"; done
# 或也可以使用此命令来获取与容器关联的所有标签
kubectl get pods --show-labels
# 检查哪些节点处于 ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \
&& kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"
# 列出被一个 pod 使用的全部 secret
kubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq
# 列出 events,按照创建时间排序
kubectl get events --sort-by=.metadata.creationTimestamp
```
<!-- ## Updating Resources -->
## 更新资源
<!-- As of version 1.11 `rolling-update` have been deprecated (see [CHANGELOG-1.11.md](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md)), use `rollout` instead. -->
从版本 1.11 开始,`rolling-update` 已被弃用(参见 [CHANGELOG-1.11.md](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md)),请使用 `rollout` 代替。
<!-- ```bash
kubectl set image deployment/frontend www=image:v2 # Rolling update "www" containers of "frontend" deployment, updating the image
kubectl rollout history deployment/frontend # Check the history of deployments including the revision
kubectl rollout undo deployment/frontend # Rollback to the previous deployment
kubectl rollout undo deployment/frontend --to-revision=2 # Rollback to a specific revision
kubectl rollout status -w deployment/frontend # Watch rolling update status of "frontend" deployment until completion
# deprecated starting version 1.11
kubectl rolling-update frontend-v1 -f frontend-v2.json # (deprecated) Rolling update pods of frontend-v1
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2 # (deprecated) Change the name of the resource and update the image
kubectl rolling-update frontend --image=image:v2 # (deprecated) Update the pods image of frontend
kubectl rolling-update frontend-v1 frontend-v2 --rollback # (deprecated) Abort existing rollout in progress
cat pod.json | kubectl replace -f - # Replace a pod based on the JSON passed into std
# Force replace, delete and then re-create the resource. Will cause a service outage.
kubectl replace --force -f ./pod.json
# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000
kubectl expose rc nginx --port=80 --target-port=8000
# Update a single-container pod's image version (tag) to v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
kubectl label pods my-pod new-label=awesome # Add a Label
kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq # Add an annotation
kubectl autoscale deployment foo --min=2 --max=10 # Auto scale a deployment "foo"
``` -->
```bash
kubectl set image deployment/frontend www=image:v2 # 滚动更新 "frontend" deployment 的 "www" 容器镜像
kubectl rollout history deployment/frontend # 检查部署的历史记录,包括版本
kubectl rollout undo deployment/frontend # 回滚到上次部署版本
kubectl rollout undo deployment/frontend --to-revision=2 # 回滚到特定部署版本
kubectl rollout status -w deployment/frontend # Watch "frontend" deployment 的滚动升级状态直到完成
# 从 1.11 版本开始弃用
kubectl rolling-update frontend-v1 -f frontend-v2.json # (弃用) 滚动升级 frontend-v1 的 pods
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2 # (弃用) 修改资源的名称并更新镜像
kubectl rolling-update frontend --image=image:v2 # (弃用) 更新 frontend 的 pods 的镜像
kubectl rolling-update frontend-v1 frontend-v2 --rollback # (弃用) 终止已经进行中的 rollout
cat pod.json | kubectl replace -f - # 通过传入到标准输入的 JSON 来替换 pod
# 强制进行替换,会删除然后再创建资源,会导致服务不可用。
kubectl replace --force -f ./pod.json
# 为多副本的 nginx 创建服务,使用 80 端口提供服务,连接到容器的 8000 端口。
kubectl expose rc nginx --port=80 --target-port=8000
# 更新单容器 pod 的镜像标签到 v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
kubectl label pods my-pod new-label=awesome # 添加标签
kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq # 添加注解
kubectl autoscale deployment foo --min=2 --max=10 # 使 "foo" deployment 自动伸缩容
```
<!-- ## Patching Resources -->
## 局部更新资源
<!-- ```bash
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}' # Partially update a node
# Update a container's image; spec.containers[*].name is required because it's a merge key
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
# Update a container's image using a json patch with positional arrays
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
# Disable a deployment livenessProbe using a json patch with positional arrays
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
# Add a new element to a positional array
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
``` -->
```bash
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}' # 部分更新 node
#更新容器的镜像;spec.containers[*].name 是必须的。因为它是一个合并 key。
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
# 使用带位置数组的 json patch 更新容器的镜像
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
# 使用带位置数组的 json patch 禁用 deployment 的 livenessProbe
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
# 在带位置数组中添加元素
kubectl patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "whatever" } }]'
```
<!-- ## Editing Resources -->
## 编辑资源
<!-- The edit any API resource in an editor. -->
在编辑器中编辑任何 API 资源
<!-- ```bash
kubectl edit svc/docker-registry # Edit the service named docker-registry
KUBE_EDITOR="nano" kubectl edit svc/docker-registry # Use an alternative editor
``` -->
```bash
kubectl edit svc/docker-registry # 编辑名为 docker-registry 的 service
KUBE_EDITOR="nano" kubectl edit svc/docker-registry # 使用其他编辑器
```
<!-- ## Scaling Resources -->
## 对资源进行伸缩
<!-- ```bash
kubectl scale --replicas=3 rs/foo # Scale a replicaset named 'foo' to 3
kubectl scale --replicas=3 -f foo.yaml # Scale a resource specified in "foo.yaml" to 3
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql # If the deployment named mysql's current size is 2, scale mysql to 3
kubectl scale --replicas=5 rc/foo rc/bar rc/baz # Scale multiple replication controllers
``` -->
```bash
kubectl scale --replicas=3 rs/foo # 将名为 'foo' 的副本集伸缩到 3 副本
kubectl scale --replicas=3 -f foo.yaml # 将在 "foo.yaml" 中的特定资源伸缩到 3 个副本
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql # 如果名为 mysql 的 deployment 的副本当前是 2,那么将它伸缩到 3
kubectl scale --replicas=5 rc/foo rc/bar rc/baz # 伸缩多个 replication controllers
```
<!-- ## Deleting Resources -->
## 删除资源
<!-- ```bash
kubectl delete -f ./pod.json # Delete a pod using the type and name specified in pod.json
kubectl delete pod,service baz foo # Delete pods and services with same names "baz" and "foo"
kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
kubectl delete pods,services -l name=myLabel --include-uninitialized # Delete pods and services, including uninitialized ones, with label name=myLabel
kubectl -n my-ns delete po,svc --all # Delete all pods and services, including uninitialized ones, in namespace my-ns,
# Delete all pods matching the awk pattern1 or pattern2
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
``` -->
```bash
kubectl delete -f ./pod.json # 删除在 pod.json 中指定的类型和名称的 pod
kubectl delete pod,service baz foo # 删除名称为 "baz" 和 "foo" 的 pod 和 service
kubectl delete pods,services -l name=myLabel # 删除包含 name=myLabel 标签的 pods 和 services
kubectl delete pods,services -l name=myLabel --include-uninitialized # 删除包含 label name=myLabel 标签的 pods 和 services,包括未初始化的
kubectl -n my-ns delete po,svc --all # 删除在 my-ns 命名空间中全部的 pods 和 services ,包括未初始化的
# 删除所有与 pattern1 或 pattern2 匹配的 pod
kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{print $1}' | xargs kubectl delete -n mynamespace pod
```
<!-- ## Interacting with running Pods -->
## 与运行中的 Pods 进行交互
<!-- ```bash
kubectl logs my-pod # dump pod logs (stdout)
kubectl logs -l name=myLabel # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod --previous # dump pod logs (stdout) for a previous instantiation of a container
kubectl logs my-pod -c my-container # dump pod container logs (stdout, multi-container case)
kubectl logs -l name=myLabel -c my-container # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod -c my-container --previous # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
kubectl logs -f my-pod # stream pod logs (stdout)
kubectl logs -f my-pod -c my-container # stream pod container logs (stdout, multi-container case)
kubectl logs -f -l name=myLabel --all-containers # stream all pods logs with label name=myLabel (stdout)
kubectl run -i --tty busybox --image=busybox -- sh # Run pod as interactive shell
kubectl attach my-pod -i # Attach to Running Container
kubectl port-forward my-pod 5000:6000 # Listen on port 5000 on the local machine and forward to port 6000 on my-pod
kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
kubectl exec my-pod -c my-container -- ls / # Run command in existing pod (multi-container case)
kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
``` -->
```bash
kubectl logs my-pod # 获取 pod 日志(标准输出)
kubectl logs -l name=myLabel # 获取 pod label name=myLabel 日志(标准输出)
kubectl logs my-pod --previous # 获取上个容器实例的 pod 日志(标准输出)
kubectl logs my-pod -c my-container # 获取 pod 的容器日志 (标准输出, 多容器的场景)
kubectl logs -l name=myLabel -c my-container # 获取 label name=myLabel pod 的容器日志 (标准输出, 多容器的场景)
kubectl logs my-pod -c my-container --previous # 获取 pod 的上个容器实例日志 (标准输出, 多容器的场景)
kubectl logs -f my-pod # 流式输出 pod 的日志 (标准输出)
kubectl logs -f my-pod -c my-container # 流式输出 pod 容器的日志 (标准输出, 多容器的场景)
kubectl logs -f -l name=myLabel --all-containers # 流式输出 label name=myLabel pod 的日志 (标准输出)
kubectl run -i --tty busybox --image=busybox -- sh # 以交互式 shell 运行 pod
kubectl attach my-pod -i # 进入到一个运行中的容器中
kubectl port-forward my-pod 5000:6000 # 在本地计算机上侦听端口 5000 并转发到 my-pod 上的端口 6000
kubectl exec my-pod -- ls / # 在已有的 pod 中运行命令(单容器的场景)
kubectl exec my-pod -c my-container -- ls / # 在已有的 pod 中运行命令(多容器的场景)
kubectl top pod POD_NAME --containers # 显示给定 pod 和容器的监控数据
```
<!-- ## Interacting with Nodes and Cluster -->
## 与节点和集群进行交互
<!-- ```bash
kubectl cordon my-node # Mark my-node as unschedulable
kubectl drain my-node # Drain my-node in preparation for maintenance
kubectl uncordon my-node # Mark my-node as schedulable
kubectl top node my-node # Show metrics for a given node
kubectl cluster-info # Display addresses of the master and services
kubectl cluster-info dump # Dump current cluster state to stdout
kubectl cluster-info dump --output-directory=/path/to/cluster-state # Dump current cluster state to /path/to/cluster-state
# If a taint with that key and effect already exists, its value is replaced as specified.
kubectl taint nodes foo dedicated=special-user:NoSchedule
``` -->
```bash
kubectl cordon my-node # 设置 my-node 节点为不可调度
kubectl drain my-node # 对 my-node 节点进行驱逐操作,为节点维护做准备
kubectl uncordon my-node # 设置 my-node 节点为可以调度
kubectl top node my-node # 显示给定 node 的指标
kubectl cluster-info # 显示 master 和 services 的地址
kubectl cluster-info dump # 将当前集群状态输出到标准输出
kubectl cluster-info dump --output-directory=/path/to/cluster-state # 将当前集群状态输出到 /path/to/cluster-state
# 如果已存在具有该键和效果的污点,则其值将按指定替换
kubectl taint nodes foo dedicated=special-user:NoSchedule
```
<!-- ### Resource types -->
### 资源类型
<!-- List all supported resource types along with their shortnames, [API group](/docs/concepts/overview/kubernetes-api/#api-groups), whether they are [namespaced](/docs/concepts/overview/working-with-objects/namespaces), and [Kind](/docs/concepts/overview/working-with-objects/kubernetes-objects): -->
列出全部支持的资源类型和它们的简称, [API group](/docs/concepts/overview/kubernetes-api/#api-groups), 无论它们是否是 [namespaced](/docs/concepts/overview/working-with-objects/namespaces), [Kind](/docs/concepts/overview/working-with-objects/kubernetes-objects)。
```bash
kubectl api-resources
```
<!-- Other operations for exploring API resources: -->
用于探索 API 资源的其他操作:
<!-- ```bash
kubectl api-resources --namespaced=true # All namespaced resources
kubectl api-resources --namespaced=false # All non-namespaced resources
kubectl api-resources -o name # All resources with simple output (just the resource name)
kubectl api-resources -o wide # All resources with expanded (aka "wide") output
kubectl api-resources --verbs=list,get # All resources that support the "list" and "get" request verbs
kubectl api-resources --api-group=extensions # All resources in the "extensions" API group
``` -->
```bash
kubectl api-resources --namespaced=true # 所有在命名空间中的资源
kubectl api-resources --namespaced=false # 所有不在命名空间中的资源
kubectl api-resources -o name # 输出简单的所有资源(只是资源名称)
kubectl api-resources -o wide # 具有扩展(又称 "wide")输出的所有资源
kubectl api-resources --verbs=list,get # 支持 "list" 和 "get" 请求动词的所有资源
kubectl api-resources --api-group=extensions # "extensions" API 组中的所有资源
```
<!-- ### Formatting output -->
### 格式化输出
<!-- To output details to your terminal window in a specific format, you can add either the `-o` or `--output` flags to a supported `kubectl` command. -->
要以特定格式将详细信息输出到终端窗口,可以将 `-o` 或 `--output` 参数添加到支持的 `kubectl` 命令。
<!-- Output format | Description
--------------| -----------
`-o=custom-columns=<spec>` | Print a table using a comma separated list of custom columns
`-o=custom-columns-file=<filename>` | Print a table using the custom columns template in the `<filename>` file
`-o=json` | Output a JSON formatted API object
`-o=jsonpath=<template>` | Print the fields defined in a [jsonpath](/docs/reference/kubectl/jsonpath) expression
`-o=jsonpath-file=<filename>` | Print the fields defined by the [jsonpath](/docs/reference/kubectl/jsonpath) expression in the `<filename>` file
`-o=name` | Print only the resource name and nothing else
`-o=wide` | Output in the plain-text format with any additional information, and for pods, the node name is included
`-o=yaml` | Output a YAML formatted API object -->
输出格式 | 描述
--------------| -----------
`-o=custom-columns=<spec>` | 使用逗号分隔的自定义列列表打印表格
`-o=custom-columns-file=<filename>` | 使用 `<filename>` 文件中的自定义列模板打印表格
`-o=json` | 输出 JSON 格式的 API 对象
`-o=jsonpath=<template>` | 打印 [jsonpath](/docs/reference/kubectl/jsonpath) 表达式中定义的字段
`-o=jsonpath-file=<filename>` | 在 `<filename>` 文件中打印由 [jsonpath](/docs/reference/kubectl/jsonpath) 表达式定义的字段。
`-o=name` | 仅打印资源名称而不打印任何其他内容
`-o=wide` | 使用任何其他信息以纯文本格式输出,对于 pod 来说,包含了节点名称
`-o=yaml` | 输出 YAML 格式的 API 对象
<!-- ### Kubectl output verbosity and debugging -->
### Kubectl 日志输出详细程度和调试
<!-- Kubectl verbosity is controlled with the `-v` or `--v` flags followed by an integer representing the log level. General Kubernetes logging conventions and the associated log levels are described [here](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md). -->
Kubectl 日志输出详细程度是通过 `-v` 或者 `--v` 来控制的,参数后跟了一个数字表示日志的级别。Kubernetes 通用的日志习惯和相关的日志级别在 [这里](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md) 有相应的描述。
<!-- Verbosity | Description
--------------| -----------
`--v=0` | Generally useful for this to *always* be visible to a cluster operator.
`--v=1` | A reasonable default log level if you don't want verbosity.
`--v=2` | Useful steady state information about the service and important log messages that may correlate to significant changes in the system. This is the recommended default log level for most systems.
`--v=3` | Extended information about changes.
`--v=4` | Debug level verbosity.
`--v=6` | Display requested resources.
`--v=7` | Display HTTP request headers.
`--v=8` | Display HTTP request contents.
`--v=9` | Display HTTP request contents without truncation of contents. -->
详细程度 | 描述
--------------| -----------
`--v=0` | 通常对此有用,*始终*对运维人员可见。
`--v=1` | 如果您不想要详细程度,则为合理的默认日志级别。
`--v=2` | 有关服务的有用稳定状态信息以及可能与系统中的重大更改相关的重要日志消息。这是大多数系统的建议默认日志级别。
`--v=3` | 有关更改的扩展信息。
`--v=4` | Debug 级别。
`--v=6` | 显示请求的资源。
`--v=7` | 显示 HTTP 请求头。
`--v=8` | 显示 HTTP 请求内容。
`--v=9` | 显示 HTTP 请求内容而不截断内容。
{{% /capture %}}
{{% capture whatsnext %}}
<!-- * Learn more about [Overview of kubectl](/docs/reference/kubectl/overview/).
* See [kubectl](/docs/reference/kubectl/kubectl/) options.
* Also [kubectl Usage Conventions](/docs/reference/kubectl/conventions/) to understand how to use it in reusable scripts.
* See more community [kubectl cheatsheets](https://github.com/dennyzhang/cheatsheet-kubernetes-A4). -->
* 学习更多关于 [kubectl 概述](/docs/reference/kubectl/overview/)。
* 查看 [kubectl](/docs/reference/kubectl/kubectl/) 选项.
* 也可以查看 [kubectl 使用约定](/docs/reference/kubectl/conventions/) 来理解如果在可以复用的脚本中使用它。
* 查看更多社区 [kubectl 备忘单](https://github.com/dennyzhang/cheatsheet-kubernetes-A4)。
{{% /capture %}}
@@ -0,0 +1,170 @@
---
title: kubectl 的用法约定
reviewers:
- janetkuo
content_template: templates/concept
---
<!--
---
title: kubectl Usage Conventions
reviewers:
- janetkuo
content_template: templates/concept
---
-->
{{% capture overview %}}
<!--
Recommended usage conventions for `kubectl`.
-->
`kubectl` 的推荐用法约定
{{% /capture %}}
{{% capture body %}}
<!--
## Using `kubectl` in Reusable Scripts
-->
## 在可重用脚本中使用 `kubectl`
<!--
For a stable output in a script:
-->
对于脚本中的稳定输出:
<!--
* Request one of the machine-oriented output forms, such as `-o name`, `-o json`, `-o yaml`, `-o go-template`, or `-o jsonpath`.
* Fully-qualify the version. For example, `jobs.v1.batch/myjob`. This will ensure that kubectl does not use its default version that can change over time.
* Specify the `--generator` flag to pin to a specific behavior when you use generator-based commands such as `kubectl run` or `kubectl expose`.
* Don't rely on context, preferences, or other implicit states.
-->
* 请求一个面向机器的输出格式,例如 `-o name``-o json``-o yaml``-o go template``-o jsonpath`
* 完全限定版本。例如 `jobs.v1.batch/myjob`。这将确保 kubectl 不会使用其默认版本,该版本会随着时间的推移而更改。
* 在使用基于生成器的命令(例如 `kubectl run` 或者 `kubectl expose`)时,指定 `--generator` 参数以固定到特定行为。
* 不要依赖上下文、首选项或其他隐式状态。
<!--
## Best Practices
-->
## 最佳实践
### `kubectl run`
<!--
For `kubectl run` to satisfy infrastructure as code:
-->
若希望 `kubectl run` 满足基础设施即代码的要求:
<!--
* Tag the image with a version-specific tag and don't move that tag to a new version. For example, use `:v1234`, `v1.2.3`, `r03062016-1-4`, rather than `:latest` (For more information, see [Best Practices for Configuration](/docs/concepts/configuration/overview/#container-images)).
* Capture the parameters in a checked-in script, or at least use `--record` to annotate the created objects with the command line for an image that is lightly parameterized.
* Check in the script for an image that is heavily parameterized.
* Switch to configuration files checked into source control for features that are needed, but not expressible via `kubectl run` flags.
* Pin to a specific [generator](#generators) version, such as `kubectl run --generator=deployment/v1beta1`.
-->
* 使用特定版本的标签标记镜像,不要将该标签移动到新版本。例如,使用 `:v1234``v1.2.3``r03062016-1-4`,而不是 `:latest`(有关详细信息,请参阅[配置的最佳实践](/docs/concepts/configuration/overview/#container-images))。
* 使用基于版本控制的脚本来记录所使用的参数,或者至少使用 `--record` 参数以便为所创建的对象添加注解,在使用轻度参数化的镜像时,记录下所使用的命令行。
* 使用基于版本控制的脚本来运行包含大量参数的镜像。
* 对于无法通过 `kubectl run` 参数来表示的功能特性,使用基于源码控制的配置文件,以记录要使用的功能特性。
* 固定到特定的[生成器](#生成器)版本,例如 `kubectl run --generator=deployment/v1beta1`
<!--
#### Generators
-->
#### 生成器
<!--
You can create the following resources using `kubectl run` with the `--generator` flag:
-->
您可以使用带有 `--generator` 参数的 `kubectl run` 命令创建如下资源:
<!--
| Resource | api group | kubectl command |
|-------------------------------------|--------------------|---------------------------------------------------|
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| Replication controller (deprecated) | v1 | `kubectl run --generator=run/v1` |
| Deployment (deprecated) | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment (deprecated) | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job (deprecated) | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob (deprecated) | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
| CronJob (deprecated) | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
-->
| 资源 | api 组 | kubectl 命令 |
|-------------------------------------|--------------------|---------------------------------------------------|
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| Replication controller (过期)) | v1 | `kubectl run --generator=run/v1` |
| Deployment (过期) | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment (过期) | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job (过期) | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob (过期) | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
| CronJob (过期) | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
<!-- {{< note >}}
`kubectl run --generator` except for `run-pod/v1` is deprecated in v1.12.
{{< /note >}} -->
{{< note >}}
v1.12 中不建议使用 `run-pod/v1` 以外的 `kubectl run --generator`
{{< /note >}}
<!--
If you do not specify a generator flag, other flags prompt you to use a specific generator. The following table lists the flags that force you to use specific generators, depending on the version of the cluster:
-->
如果不指定 generator 参数,其他参数将提示您使用特定的生成器。下表列出了强制您使用特定生成器的参数,具体取决于集群的版本:
<!--
| Generated Resource | Cluster v1.4 and later | Cluster v1.3 | Cluster v1.2 | Cluster v1.1 and earlier |
|:----------------------:|------------------------|-----------------------|--------------------------------------------|--------------------------------------------|
| Pod | `--restart=Never` | `--restart=Never` | `--generator=run-pod/v1` | `--restart=OnFailure` OR `--restart=Never` |
| Replication Controller | `--generator=run/v1` | `--generator=run/v1` | `--generator=run/v1` | `--restart=Always` |
| Deployment | `--restart=Always` | `--restart=Always` | `--restart=Always` | N/A |
| Job | `--restart=OnFailure` | `--restart=OnFailure` | `--restart=OnFailure` OR `--restart=Never` | N/A |
| Cron Job | `--schedule=<cron>` | N/A | N/A | N/A |
-->
| 生成的资源 | 集群版本 v1.4 及以后版本 | 集群版本 v1.3 | 集群版本 v1.2 | 集群版本 v1.1 及更早 |
|:----------------------:|------------------------|-----------------------|--------------------------------------------|--------------------------------------------|
| Pod | `--restart=Never` | `--restart=Never` | `--generator=run-pod/v1` | `--restart=OnFailure``--restart=Never` |
| Replication Controller | `--generator=run/v1` | `--generator=run/v1` | `--generator=run/v1` | `--restart=Always` |
| Deployment | `--restart=Always` | `--restart=Always` | `--restart=Always` | N/A |
| Job | `--restart=OnFailure` | `--restart=OnFailure` | `--restart=OnFailure``--restart=Never` | N/A |
| Cron Job | `--schedule=<cron>` | N/A | N/A | N/A |
{{< note >}}
<!--
These flags use a default generator only when you have not specified any flag.
This means that when you combine `--generator` with other flags the generator that you specified later does not change. For example, in a cluster v1.4, if you initially specify
`--restart=Always`, a Deployment is created; if you later specify `--restart=Always`
and `--generator=run/v1`, a Replication Controller is created.
This enables you to pin to a specific behavior with the generator,
even when the default generator is changed later.
-->
只有在未指定任何参数时,这些参数才使用默认生成器。
这意味着,当您将 `--generator` 与其他参数组合时,随后指定的生成器不会更改。
例如,在集群版本 v1.4 中,如果最初指定了 `--restart=always`,则会创建 Deployment;如果后来指定了 `--restart=always``--generator=run/v1`,则会创建 Replication Controller。
这使您能够将生成器固定到特定的行为,即使在以后更改默认生成器时也是如此。
{{< /note >}}
<!--
The flags set the generator in the following order: first the `--schedule` flag, then the `--restart` policy flag, and finally the `--generator` flag.
-->
这些参数按以下顺序设置生成器:首先是 `--schedule` 参数,然后是 `--restart` 策略参数,最后是 `--generator` 参数。
<!--
To check the final resource that was created, use the `--dry-run`
flag, which provides the object to be submitted to the cluster.
-->
要检查最终所创建的资源,请使用 `--dry run` 参数;该参数可以提供将要提交到集群的对象。
### `kubectl apply`
<!--
* You can use `kubectl apply` to create or update resources. For more information about using kubectl apply to update resources, see [Kubectl Book](https://kubectl.docs.kubernetes.io).
-->
* 您可以使用 `kubectl apply` 命令创建或更新资源。有关使用 kubectl apply 更新资源的详细信息,请参阅 [Kubectl 文档](https://kubectl.docs.kubernetes.io)。
{{% /capture %}}
@@ -1,228 +1,417 @@
---
approvers:
title: 适用于 Docker 用户的 kubectl
content_template: templates/concept
reviewers:
- brendandburns
- thockin
title: Docker 用户使用 kubectl 命令指南
---
在本文中,我们将向 docker-cli 用户介绍 Kubernetes 命令行如何与 api 进行交互。该命令行工具——kubectl,被设计成 docker-cli 用户所熟悉的样子,但是它们之间又存在一些必要的差异。该文档将向您展示每个 docker 子命令和 kubectl 与其等效的命令。
{{< toc >}}
#### docker run
如何运行一个 nginx Deployment 并将其暴露出来? 查看 [kubectl run](/docs/reference/generated/kubectl/kubectl-commands/#run) 。
使用 docker 命令:
```shell
$ docker run -d --restart=always -e DOMAIN=cluster --name nginx-app -p 80:80 nginx
a9ec34d9878748d2f33dc20cb25c714ff21da8d40558b45bfaec9955859075d0
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9ec34d98787 nginx "nginx -g 'daemon of 2 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp, 443/tcp nginx-app
```
使用 kubectl 命令:
<!--
# start the pod running nginx
<!--
---
title: kubectl for Docker Users
content_template: templates/concept
reviewers:
- brendandburns
- thockin
---
-->
{{% capture overview %}}
<!--
You can use the Kubernetes command line tool kubectl to interact with the API Server. Using kubectl is straightforward if you are familiar with the Docker command line tool. However, there are a few differences between the docker commands and the kubectl commands. The following sections show a docker sub-command and describe the equivalent kubectl command.
-->
您可以使用 Kubernetes 命令行工具 kubectl 与 API 服务器进行交互。如果您熟悉 Docker 命令行工具,则使用 kubectl 非常简单。但是,docker 命令和 kubectl 命令之间有一些区别。以下显示了 docker 子命令,并描述了等效的 kubectl 命令。
{{% /capture %}}
{{% capture body %}}
## docker run
<!--
To run an nginx Deployment and expose the Deployment, see [kubectl run](/docs/reference/generated/kubectl/kubectl-commands/#run).
-->
要运行 nginx 部署并将其暴露,请参见 [kubectl 运行](/docs/reference/generated/kubectl/kubectl-commands/#run)。
docker:
```shell
# 启动运行 nginx 的 pod
$ kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
docker run -d --restart=always -e DOMAIN=cluster --name nginx-app -p 80:80 nginx
```
```
55c103fa129692154a7652490236fee9be47d70a8dd562281ae7d2f9a339a6db
```
```shell
docker ps
```
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55c103fa1296 nginx "nginx -g 'daemon of…" 9 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp nginx-app
```
kubectl:
<!--
```shell
# start the pod running nginx
kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
```
-->
```shell
# 启动运行 nginx 的 Pod
kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
```
```
deployment "nginx-app" created
```
在 1.2 及以上版本的 Kubernetes 集群中,使用`kubectl run` 命令将创建一个名为 "nginx-app" 的 Deployment。如果您运行的是老版本,将会创建一个 replication controller。
如果您想沿用旧的行为,使用 `--generation=run/v1` 参数,这样就会创建 replication controller。查看 [`kubectl run`](/docs/reference/generated/kubectl/kubectl-commands/#run) 获取更多详细信息。
{{< note >}}
<!--
# expose a port through with a service
`kubectl` commands print the type and name of the resource created or mutated, which can then be used in subsequent commands. You can expose a new Service after a Deployment is created.
-->
`kubectl` 命令打印创建或突变资源的类型和名称,然后可以在后续命令中使用。部署后,您可以公开新服务。
{{< /note >}}
<!--
```shell
# 通过服务暴露端口
$ kubectl expose deployment nginx-app --port=80 --name=nginx-http
# expose a port through with a service
kubectl expose deployment nginx-app --port=80 --name=nginx-http
```
-->
```shell
# 通过服务公开端口
kubectl expose deployment nginx-app --port=80 --name=nginx-http
```
```
service "nginx-http" exposed
```
在 kubectl 命令中,我们创建了一个 [Deployment](/docs/concepts/workloads/controllers/deployment/),这将保证有 N 个运行 nginx 的 podN 代表 spec 中声明的 replica 数,默认为 1)。我们还创建了一个 [service](/docs/user-guide/services),使用 selector 匹配具有相应的 selector 的 Deployment。查看[快速开始](/docs/user-guide/quick-start)获取更多信息。
<!--
By using kubectl, you can create a [Deployment](/docs/concepts/workloads/controllers/deployment/) to ensure that N pods are running nginx, where N is the number of replicas stated in the spec and defaults to 1. You can also create a [service](/docs/concepts/services-networking/service/) with a selector that matches the pod labels. For more information, see [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster).
-->
在 kubectl 命令中,我们创建了一个 [Deployment](/docs/concepts/workloads/controllers/deployment/),这将保证有 N 个运行 nginx 的 pod(N 代表 spec 中声明的 replica 数,默认为 1)。我们还创建了一个 [service](/docs/concepts/services-networking/service/),其选择器与容器标签匹配。查看[使用服务访问群集中的应用程序](/docs/tasks/access-application-cluster/service-access-application-cluster) 获取更多信息。
默认情况下镜像会在后台运行,与`docker run -d ...` 类似,如果您想在前台运行,使用:
<!--
By default images run in the background, similar to `docker run -d ...`. To run things in the foreground, use:
-->
默认情况下镜像会在后台运行,与 `docker run -d ...` 类似,如果您想在前台运行,使用:
```shell
kubectl run [-i] [--tty] --attach <name> --image=<image>
```
`docker run ...` 不同的是,如果指定了 `--attach` ,我们将连接到 `stdin``stdout``stderr`,而不能控制具体连接到哪个输出流(`docker -a ...`)。
<!--
Unlike `docker run ...`, if you specify `--attach`, then you attach `stdin`, `stdout` and `stderr`. You cannot control which streams are attached (`docker -a ...`).
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
-->
`docker run ...` 不同的是,如果指定了 `--attach` ,我们将连接到 `stdin``stdout``stderr`,而不能控制具体连接到哪个输出流(`docker -a ...`)。要从容器中退出,可以输入 Ctrl + P,然后按 Ctrl + Q。
因为我们使用 Deployment 启动了容器,如果您终止了连接到的进程(例如 `ctrl-c`),容器将会重启,这跟 `docker run -it` 不同。
<!--
Because the kubectl run command starts a Deployment for the container, the Deployment restarts if you terminate the attached process by using Ctrl+C, unlike `docker run -it`.
To destroy the Deployment and its pods you need to run `kubectl delete deployment <name>`.
-->
因为我们使用 Deployment 启动了容器,如果您终止连接到的进程(例如 `ctrl-c`),容器将会重启,这跟 `docker run -it` 不同。
如果想销毁该 Deployment(和它的 pod),您需要运行 `kubectl delete deployment <name>`
#### docker ps
## docker ps
<!--
To list what is currently running, see [kubectl get](/docs/reference/generated/kubectl/kubectl-commands/#get).
-->
如何列出哪些正在运行?查看 [kubectl get](/docs/reference/generated/kubectl/kubectl-commands/#get)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9ec34d98787 nginx "nginx -g 'daemon of About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp nginx-app
docker ps -a
```
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14636241935f ubuntu:16.04 "echo test" 5 seconds ago Exited (0) 5 seconds ago cocky_fermi
55c103fa1296 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp nginx-app
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl get po
NAME READY STATUS RESTARTS AGE
nginx-app-5jyvm 1/1 Running 0 1h
kubectl get po
```
```
NAME READY STATUS RESTARTS AGE
nginx-app-8df569cb7-4gd89 1/1 Running 0 3m
ubuntu 0/1 Completed 0 20s
```
#### docker attach
## docker attach
<!--
To attach a process that is already running in a container, see [kubectl attach](/docs/reference/generated/kubectl/kubectl-commands/#attach).
-->
如何连接到已经运行在容器中的进程?查看 [kubectl attach](/docs/reference/generated/kubectl/kubectl-commands/#attach)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9ec34d98787 nginx "nginx -g 'daemon of 8 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, 443/tcp nginx-app
$ docker attach a9ec34d98787
...
docker ps
```
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55c103fa1296 nginx "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp nginx-app
```
使用 kubectl 命令:
```shell
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app-5jyvm 1/1 Running 0 10m
$ kubectl attach -it nginx-app-5jyvm
docker attach 55c103fa1296
...
```
#### docker exec
kubectl:
```shell
kubectl get pods
```
```
NAME READY STATUS RESTARTS AGE
nginx-app-5jyvm 1/1 Running 0 10m
```
```shell
kubectl attach -it nginx-app-5jyvm
...
```
<!--
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
-->
要从容器中分离,可以输入 Ctrl + P,然后按 Ctrl + Q。
## docker exec
<!--
To execute a command in a container, see [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec).
-->
如何在容器中执行命令?查看 [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9ec34d98787 nginx "nginx -g 'daemon of 8 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, 443/tcp nginx-app
$ docker exec a9ec34d98787 cat /etc/hostname
a9ec34d98787
docker ps
```
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55c103fa1296 nginx "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes 0.0.0.0:80->80/tcp nginx-app
```
```shell
docker exec 55c103fa1296 cat /etc/hostname
```
```
55c103fa1296
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl get po
kubectl get po
```
```
NAME READY STATUS RESTARTS AGE
nginx-app-5jyvm 1/1 Running 0 10m
$ kubectl exec nginx-app-5jyvm -- cat /etc/hostname
```
```shell
kubectl exec nginx-app-5jyvm -- cat /etc/hostname
```
```
nginx-app-5jyvm
```
<!--
To use interactive commands.
-->
执行交互式命令怎么办?
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker exec -ti a9ec34d98787 /bin/sh
docker exec -ti 55c103fa1296 /bin/sh
# exit
```
使用 kubectl 命令:
kubectl:
```shell
$ kubectl exec -ti nginx-app-5jyvm -- /bin/sh
kubectl exec -ti nginx-app-5jyvm -- /bin/sh
# exit
```
<!--
For more information, see [Get a Shell to a Running Container](/docs/tasks/debug-application-cluster/get-shell-running-container/).
-->
更多信息请查看[获取运行中容器的 Shell 环境](/docs/tasks/kubectl/get-shell-running-container/)。
#### docker logs
## docker logs
<!--
To follow stdout/stderr of a process that is running, see [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs).
-->
如何查看运行中进程的 stdout/stderr?查看 [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker logs -f a9e
docker logs -f a9e
```
```
192.168.9.1 - - [14/Jul/2015:01:04:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
192.168.9.1 - - [14/Jul/2015:01:04:03 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl logs -f nginx-app-zibvs
kubectl logs -f nginx-app-zibvs
```
```
10.240.63.110 - - [14/Jul/2015:01:09:01 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
```
<!--
There is a slight difference between pods and containers; by default pods do not terminate if their processes exit. Instead the pods restart the process. This is similar to the docker run option `--restart=always` with one major difference. In docker, the output for each invocation of the process is concatenated, but for Kubernetes, each invocation is separate. To see the output from a previous run in Kubernetes, do this:
-->
现在是时候提一下 pod 和容器之间的细微差别了;默认情况下如果 pod 中的进程退出 pod 也不会终止,相反它将会重启该进程。这类似于 docker run 时的 `--restart=always` 选项, 这是主要差别。在 docker 中,进程的每个调用的输出都是被连接起来的,但是对于 kubernetes,每个调用都是分开的。要查看以前在 kubernetes 中执行的输出,请执行以下操作:
```shell
$ kubectl logs --previous nginx-app-zibvs
kubectl logs --previous nginx-app-zibvs
```
```
10.240.63.110 - - [14/Jul/2015:01:09:01 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
```
查看[记录和监控集群活动](/docs/concepts/cluster-administration/logging/)获取更多信息。
#### docker stop 和 docker rm
<!--
For more information, see [Logging Architecture](/docs/concepts/cluster-administration/logging/).
-->
查看[日志架构](/docs/concepts/cluster-administration/logging/)获取更多信息。
## docker stop and docker rm
<!--
To stop and delete a running process, see [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete).
-->
如何停止和删除运行中的进程?查看 [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker ps
docker ps
```
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9ec34d98787 nginx "nginx -g 'daemon of 22 hours ago Up 22 hours 0.0.0.0:80->80/tcp, 443/tcp nginx-app
$ docker stop a9ec34d98787
a9ec34d98787
$ docker rm a9ec34d98787
a9ec34d98787 nginx "nginx -g 'daemon of" 22 hours ago Up 22 hours 0.0.0.0:80->80/tcp, 443/tcp nginx-app
```
```shell
docker stop a9ec34d98787
```
```
a9ec34d98787
```
```shell
docker rm a9ec34d98787
```
```
a9ec34d98787
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl get deployment nginx-app
kubectl get deployment nginx-app
```
```
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-app 1 1 1 1 2m
$ kubectl get po -l run=nginx-app
```
```shell
kubectl get po -l run=nginx-app
```
```
NAME READY STATUS RESTARTS AGE
nginx-app-2883164633-aklf7 1/1 Running 0 2m
$ kubectl delete deployment nginx-app
```
```shell
kubectl delete deployment nginx-app
```
```
deployment "nginx-app" deleted
$ kubectl get po -l run=nginx-app
```
```shell
kubectl get po -l run=nginx-app
# Return nothing
```
{{< note >}}
<!--
When you use kubectl, you don't delete the pod directly.You have to first delete the Deployment that owns the pod. If you delete the pod directly, the Deployment recreates the pod.
-->
请注意,我们不直接删除 pod。使用 kubectl 命令,我们要删除拥有该 pod 的 Deployment。如果我们直接删除 podDeployment 将会重新创建该 pod。
{{< /note >}}
#### docker login
## docker login
<!--
There is no direct analog of `docker login` in kubectl. If you are interested in using Kubernetes with a private registry, see [Using a Private Registry](/docs/concepts/containers/images/#using-a-private-registry).
-->
在 kubectl 中没有对 `docker login` 的直接模拟。如果您有兴趣在私有镜像仓库中使用 Kubernetes,请参阅[使用私有镜像仓库](/docs/concepts/containers/images/#using-a-private-registry)。
#### docker version
## docker version
如何查看客户端和服务端的版本?查看 [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version)。
<!--
To get the version of client and server, see [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version).
-->
如何查看客户端和服务端的版本?查看 [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker version
docker version
```
```
Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
@@ -235,22 +424,35 @@ Git commit (server): 0baf609
OS/Arch (server): linux/amd64
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl version
kubectl version
```
```
Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.9+a3d1dfa6f4335", GitCommit:"9b77fed11a9843ce3780f70dd251e92901c43072", GitTreeState:"dirty", BuildDate:"2017-08-29T20:32:58Z", OpenPaasKubernetesVersion:"v1.03.02", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.9+a3d1dfa6f4335", GitCommit:"9b77fed11a9843ce3780f70dd251e92901c43072", GitTreeState:"dirty", BuildDate:"2017-08-29T20:32:58Z", OpenPaasKubernetesVersion:"v1.03.02", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}
```
#### docker info
## docker info
如何获取有关环境和配置的各种信息?查看 [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info)。
<!--
To get miscellaneous information about the environment and configuration, see [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info).
-->
如何获取有关环境和配置的各种信息?查看 [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info)。
<!--
docker:
-->
使用 docker 命令:
```shell
$ docker info
docker info
```
```
Containers: 40
Images: 168
Storage Driver: aufs
@@ -269,10 +471,15 @@ ID: ADUV:GCYR:B3VJ:HMPO:LNPQ:KD5S:YKFQ:76VN:IANZ:7TFV:ZBF4:BYJO
WARNING: No swap limit support
```
<!--
kubectl:
-->
使用 kubectl 命令:
```shell
$ kubectl cluster-info
kubectl cluster-info
```
```
Kubernetes master is running at https://108.59.85.141
KubeDNS is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/kube-dns/proxy
kubernetes-dashboard is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
@@ -280,3 +487,4 @@ Grafana is running at https://108.59.85.141/api/v1/namespaces/kube-system/servic
Heapster is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/monitoring-heapster/proxy
InfluxDB is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy
```
{{% /capture %}}
+99 -19
View File
@@ -1,17 +1,57 @@
---
title: JSONPath 支持
content_template: templates/concept
weight: 25
---
<!--
---
title: JSONPath Support
content_template: templates/concept
weight: 25
---
-->
JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。
除了原始的 JSONPath 语法之外,我们还添加了三个函数:
{{% capture overview %}}
<!--
Kubectl supports JSONPath template.
-->
Kubectl 支持 JSONPath 模板。
{{% /capture %}}
1. `$` 运算符是可选的,因为表达式默认情况下始终从根对象开始。
2. 我们可以使用 `""` 来引用 JSONPath 表达式中的文本。
3. 我们可以使用 `range` 运算符来迭代列表。
{{% capture body %}}
结果对象使用 String() 函数打印。
<!--
JSONPath template is composed of JSONPath expressions enclosed by curly braces {}.
Kubectl uses JSONPath expressions to filter on specific fields in the JSON object and format the output.
In addition to the original JSONPath template syntax, the following functions and syntax are valid:
-->
JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSONPath 表达式来过滤 JSON 对象中的特定字段并格式化输出。除了原始的 JSONPath 模板语法,以下函数和语法也是有效的:
给定输入:
<!--
1. Use double quotes to quote text inside JSONPath expressions.
2. Use the `range`, `end` operators to iterate lists.
3. Use negative slice indices to step backwards through a list. Negative indices do not "wrap around" a list and are valid as long as `-index + listLength >= 0`.
-->
1. 使用双引号将 JSONPath 表达式内的文本引起来。
2. 使用 `range``end` 运算符来迭代列表。
3. 使用负片索引后退列表。负索引不会"环绕"列表,并且只要 `-index + listLength> = 0` 就有效。
{{< note >}}
<!--
- The `$` operator is optional since the expression always starts from the root object by default.
- The result object is printed as its String() function.
-->
- `$` 运算符是可选的,因为默认情况下表达式总是从根对象开始。
- 结果对象将作为其 String() 函数输出。
{{< /note >}}
<!--
Given the JSON input:
-->
给定 JSON 输入:
```json
{
@@ -49,15 +89,55 @@ JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。
]
}
```
| 函数 | 描述 | 示例 | 结果 |
| ------------------- | ---------- | ------------------------------------------ | ------------------------------------------ |
| `text` | 纯文本 | `kind is {.kind}` | `kind is List` |
| `@` | 当前对象 | `{@}` | 与输入相同 |
| `.` 或者 `[]` | 子运算符 | `{.kind}` 或者 `{['kind']}` | `List` |
| `..` | 递归下降 | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e` |
| `*` | 通配符,获取所有对象 | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]` |
| `[start:end :step]` | 下标运算符 | `{.users[0].name}` | `myself` |
| `[,]` | 并集运算符 | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]` |
| `?()` | 过滤 | `{.users[?(@.name=="e2e")].user.password}` | `secret` |
| `range`, `end` | 迭代列表 | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]` |
| `''` | 引用解释执行字符串 | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2` |
<!--
Function | Description | Example | Result
--------------------|---------------------------|-----------------------------------------------------------------|------------------
`text` | the plain text | `kind is {.kind}` | `kind is List`
`@` | the current object | `{@}` | the same as input
`.` or `[]` | child operator | `{.kind}` or `{['kind']}` | `List`
`..` | recursive descent | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e`
`*` | wildcard. Get all objects | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]`
`[start:end :step]` | subscript operator | `{.users[0].name}` | `myself`
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
`range`, `end` | iterate list | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
`''` | quote interpreted string | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
-->
函数 | 描述 | 示例 | 结果
--------------------|---------------------------|-----------------------------------------------------------------|------------------
`text` | 纯文本 | `kind is {.kind}` | `kind is List`
`@` | 当前对象 | `{@}` | 与输入相同
`.` or `[]` | 子运算符 | `{.kind}` or `{['kind']}` | `List`
`..` | 递归下降 | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e`
`*` | 通配符。获取所有对象 | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]`
`[start:end :step]` | 下标运算符 | `{.users[0].name}` | `myself`
`[,]` | 并集运算符 | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
`?()` | 过滤 | `{.users[?(@.name=="e2e")].user.password}` | `secret`
`range`, `end` | 迭代列表 | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
`''` | 引用解释执行字符串 | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
<!--
Examples using `kubectl` and JSONPath expressions:
-->
使用 `kubectl` 和 JSONPath 表达式的示例:
```shell
kubectl get pods -o json
kubectl get pods -o=jsonpath='{@}'
kubectl get pods -o=jsonpath='{.items[0]}'
kubectl get pods -o=jsonpath='{.items[0].metadata.name}'
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
```
<!--
On Windows, you must _double_ quote any JSONPath template that contains spaces (not single quote as shown above for bash). This in turn means that you must use a single quote or escaped double quote around any literals in the template. For example:
-->
在 Windows 上,您必须 _double_ 引用任何包含空格的 JSONPath 模板(不是上面 bash 所示的单引号)。反过来,这意味着您必须在模板中的所有文字周围使用单引号或转义的双引号。例如:
```cmd
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}"
```
{{% /capture %}}
@@ -0,0 +1,10 @@
---
title: kubectl 命令
---
<!-- ---
title: kubectl Commands
--- -->
<!-- [kubectl Command Reference](/docs/reference/generated/kubectl/kubectl-commands/) -->
[kubectl 命令参考](/docs/reference/generated/kubectl/kubectl-commands/)
@@ -1,287 +0,0 @@
---
approvers:
- hw-qiaolei
title: kubectl概述
---
kubectl是用于针对Kubernetes集群运行命令的命令行接口。本概述涵盖`kubectl`语法,描述命令操作,并提供常见的示例。有关每个命令的详细信息,包括所有支持的flags和子命令,请参考[kubectl](/docs/user-guide/kubectl)相关文档。有关安装说明,请参阅[安装kubectl](/docs/tasks/kubectl/install/)。
## 语法
从您的终端窗口使用以下语法运行`kubectl`命令:
```shell
kubectl [command] [TYPE] [NAME] [flags]
```
其中commandTYPENAME,和flags分别是:
* `command`: 指定要在一个或多个资源进行操作,例如`create``get``describe``delete`
* `TYPE`:指定[资源类型](#资源类型)。资源类型区分大小写,您可以指定单数,复数或缩写形式。例如,以下命令产生相同的输出:
$ kubectl get pod pod1
$ kubectl get pods pod1
$ kubectl get po pod1
`NAME`:指定资源的名称。名称区分大小写。如果省略名称,则会显示所有资源的详细信息,比如`$ kubectl get pods`
在多个资源上执行操作时,可以按类型和名称指定每个资源,或指定一个或多个文件:
* 按类型和名称指定资源:
* 要分组资源,如果它们都是相同的类型:`TYPE1 name1 name2 name<#>`.<br/>
例: `$ kubectl get pod example-pod1 example-pod2`
* 要分别指定多种资源类型: `TYPE1/name1 TYPE1/name2 TYPE2/name3 TYPE<#>/name<#>`.<br/>
例: `$ kubectl get pod/example-pod1 replicationcontroller/example-rc1`
使用一个或多个文件指定资源: `-f file1 -f file2 -f file<#>` 使用[YAML而不是JSON](/docs/concepts/configuration/overview/#general-configuration-tips),因为YAML往往更加用户友好,特别是对于配置文件。<br/>
例:$ kubectl get pod -f ./pod.yaml
* flags:指定可选标志。例如,您可以使用`-s``--serverflags`来指定Kubernetes API服务器的地址和端口。
**重要提示**:从命令行指定的标志将覆盖默认值和任何相应的环境变量。
如果您需要帮助,只需从终端窗口运行`kubectl help`
## 操作
下表包括所有kubectl操作的简短描述和一般语法:
Operation | Syntax | Description
-------------------- | -------------------- | --------------------
`annotate` | `kubectl annotate (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | 添加或更新一个或多个资源的注解。
`api-versions` | `kubectl api-versions [flags]` | 列出可用的API版本。
`apply` | `kubectl apply -f FILENAME [flags]`| 对文件或标准输入流更改资源应用配置。
`attach` | `kubectl attach POD -c CONTAINER [-i] [-t] [flags]` | attach 到正在运行的容器来查看输出流或与容器(stdin)进行交互。
`autoscale` | `kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]` | 自动弹性伸缩一组被replication controller管理的pods。
`cluster-info` | `kubectl cluster-info [flags]` | 显示有关集群中master节点和服务的端点信息。
`config` | `kubectl config SUBCOMMAND [flags]` | 修改kubeconfig文件。有关详细信息,请参阅各个子命令。
`create` | `kubectl create -f FILENAME [flags]` | 从文件或stdin创建一个或多个资源。
`delete` | `kubectl delete (-f FILENAME | TYPE [NAME | /NAME | -l label | --all]) [flags]` | 从文件,stdin或指定selector,名称,资源选择器或资源中删除资源。
`describe` | `kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | /NAME | -l label]) [flags]` | 显示一个或多个资源的详细状态。
`edit` | `kubectl edit (-f FILENAME | TYPE NAME | TYPE/NAME) [flags]` | 使用默认编辑器编辑和更新服务器上一个或多个资源的定义。
`exec` | `kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]` | 对pod中的容器执行命令
`explain` | `kubectl explain [--include-extended-apis=true] [--recursive=false] [flags]` | 获取各种资源的文档。例如 pods, nodes, services 等.
`expose` | `kubectl expose (-f FILENAME | TYPE NAME | TYPE/NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [----external-ip=external-ip-of-service] [--type=type] [flags]` | 将暴露replication controller, service, 或者pod为新的Kubernetes服务。
`get` | `kubectl get (-f FILENAME | TYPE [NAME | /NAME | -l label]) [--watch] [--sort-by=FIELD] [[-o | --output]=OUTPUT_FORMAT] [flags]` | 列出一个或多个资源。
`label` | `kubectl label (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | 添加或更新一个或多个资源的标签
`logs` | `kubectl logs POD [-c CONTAINER] [--follow] [flags]` | 在pod的容器中打印日志。
`patch` | `kubectl patch (-f FILENAME | TYPE NAME | TYPE/NAME) --patch PATCH [flags]` | 使用strategic merge patch程序更新资源的一个或多个字段。
`port-forward` | `kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]` | 将一个或多个本地端口转发到pod。
`proxy` | `kubectl proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix] [flags]` | 运行一个代理到Kubernetes API服务器。
`replace` | `kubectl replace -f FILENAME` | 从文件或stdin替换资源。
`rolling-update` | `kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE | -f NEW_CONTROLLER_SPEC) [flags]` | 通过逐步替换指定的replication controller及其pod来执行滚动更新。
`run` | `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [flags]` | 在集群上运行指定的镜像。
`scale` | `kubectl scale (-f FILENAME | TYPE NAME | TYPE/NAME) --replicas=COUNT [--resource-version=version] [--current-replicas=count] [flags]` | 更新指定replication controller的副本数量。
`version` | `kubectl version [--client] [flags]` | 显示在客户端和服务器上运行的Kubernetes版本。
请记住:有关命令操作的更多信息,请参阅[kubectl](/docs/user-guide/kubectl)参考文档。
## 资源类型
下表包括所有支持的资源类型及其缩写别名的列表:
资源类型 | 缩写别名
-------------------- | --------------------
`apiservices` |
`certificatesigningrequests` |`csr`
`clusters` |
`clusterrolebindings` |
`clusterroles` |
`componentstatuses` |`cs`
`configmaps` |`cm`
`controllerrevisions` |
`cronjobs` |
`customresourcedefinition` |`crd`, `crds`
`daemonsets` |`ds`
`deployments` |`deploy`
`endpoints` |`ep`
`events` |`ev`
`horizontalpodautoscalers` |`hpa`
`ingresses` |`ing`
`jobs` |
`limitranges` |`limits`
`namespaces` |`ns`
`networkpolicies` |`netpol`
`nodes` |`no`
`persistentvolumeclaims` |`pvc`
`persistentvolumes` |`pv`
`poddisruptionbudget` |`pdb`
`podpreset` |
`pods` |`po`
`podsecuritypolicies` |`psp`
`podtemplates` |
`replicasets` |`rs`
`replicationcontrollers` |`rc`
`resourcequotas` |`quota`
`rolebindings` |
`roles` |
`secrets` |
`serviceaccounts` |`sa`
`services` |`svc`
`statefulsets` |
`storageclasses` |
## 输出选项
请使用以下部分查看如何格式化或排序某些命令的输出的信息,有关哪些命令支持各种输出选项的详细信息,请参阅[kubectl](/docs/user-guide/kubectl)参考文档。
### 格式化输出
所有kubectl命令的默认输出格式是可读的纯文本格式。要以特定格式将详细信息输出到终端窗口,您可以将一个`-o`或多个`-output`标志添加到支持的`kubectl`命令中。
#### 语法
```shell
kubectl [command] [TYPE] [NAME] -o=<output_format>
```
根据kubectl操作,支持以下输出格式:
输出格式 | 描述
--------------| -----------
`-o=custom-columns=<spec>` | 输入使用逗号分隔的列表打印表格 [custom columns](#custom-columns)。
`-o=custom-columns-file=<filename>` | 使用文件中的[自定义列模板](#custom-columns)打印表`<filename>`
`-o=json` | 输出JSON格式的API对象。
`-o=jsonpath=<template>` | 打印在[jsonpath](/docs/user-guide/jsonpath)表达式中定义的字段
`-o=jsonpath-file=<filename>` | 打印由文件中的[jsonpath](/docs/user-guide/jsonpath)表达式定义的字段`<filename>`
`-o=name` | 仅打印资源名称,没有其他的。
`-o=wide` | 以纯文本格式输出任何附加信息。对于pod,包括节点名称。
`-o=yaml` | 输出YAML格式的API对象。
例子
在此示例中,以下命令将单个pod的详细信息作为YAML格式化对象输出:
`$ kubectl get pod web-pod-13je7 -o=yaml`
记住:有关每个命令支持哪种输出格式的详细信息,请参阅kubectl参考文档。
自定义列
要定义自定义列并仅将所需的详细信息输出到表中,可以使用该custom-columns选项。您可以选择内联定义自定义列或使用模板文件:`-o=custom-columns=<spec>``-o=custom-columns-file=<filename>`
##### 例子
一致:
```shell
$ kubectl get pods <pod-name> -o=custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion
```
模版文件:
```shell
$ kubectl get pods <pod-name> -o=custom-columns-file=template.txt
```
`template.txt`文件包含:
```
NAME RSRC
metadata.name metadata.resourceVersion
```
运行任一命令的结果是:
```shell
NAME RSRC
submit-queue 610995
```
### 排序列表对象
要将对象列表在终端窗口中排序输出,可以将该`--sort-by`标志添加到支持的`kubectl`命令中。通过使用`--sort-by`标志指定任何数字或字符串字段来对对象进行排序。要指定一个字段,请使用[jsonpath](/docs/user-guide/jsonpath)表达式。
#### 语法
```shell
kubectl [command] [TYPE] [NAME] --sort-by=<jsonpath_exp>
```
##### 例子
打印按名称排序的列表,请运行:
`$ kubectl get pods --sort-by=.metadata.name`
## 示例:常用操作
使用以下一组示例来帮助您熟悉运行常用kubectl操作:
```shell
// 使用在example-service.yaml中的定义创建一个service.
$ kubectl create -f example-service.yaml
// 使用在example-controller.yaml中的定义创建一个replication controller.
$ kubectl create -f example-controller.yaml
// 使用在<directory>目录下的any .yaml, .yml, or .json文件创建对象.
$ kubectl create -f <directory>
```
`kubectl get` - 列出一个或更多资源.
```shell
// 使用文本格式列出所有的pods.
$ kubectl get pods
// 使用文本格式列出所有的信息,包含一些额外的信息(比如节点名称).
$ kubectl get pods -o wide
// 使用文本格式列出指定名称的replicationcontroller. 注: 你可以缩短 'replicationcontroller' 资源类型使用别名 'rc'.
$ kubectl get replicationcontroller <rc-name>
// 使用文本格式列出所有的rc,services.
$ kubectl get rc,services
```
```
`kubectl describe` - 显示一个或多个资源的详情状态.
```shell
// 显示指定节点名称的详情信息.
$ kubectl describe nodes <node-name>
// 显示指定pods名称的详情信息.
$ kubectl describe pods/<pod-name>
// 显示所有被名称为<rc-name>的replication controller管理的所有pods的详情信息.
// 请记住: 任何被replication controller的pod的名称前缀为replication controller的名称.
$ kubectl describe pods <rc-name>
```
`kubectl delete` - 从文件, stdin,或者指定的label selectors, 名称,资源选择器, 或者资源去删除资源.
```shell
// 通过 pod.yaml 文件中的资源类型和名称删除一个pod.
$ kubectl delete -f pod.yaml
// 删除所有label名称为name=<label-name>的pods和services.
$ kubectl delete pods,services -l name=<label-name>
// 删除所有pods.
$ kubectl delete pods --all
```
`kubectl exec` - 针对pod中的某个容器执行命令.
```shell
// 在名称为<pod-name>的pod允许 'date' 命令获得输出. 默认返回的是pod中第一个容器的终端.
$ kubectl exec <pod-name> date
// 在<pod-name>的pod中的<container-name>容器中运行'date'获取输出.
$ kubectl exec <pod-name> -c <container-name> date
// 从名称为<pod-name>的pod获取一个交互的终端和运行/bin/bash. 默认返回的是pod中第一个容器的终端.
$ kubectl exec -ti <pod-name> /bin/bash
```
`kubectl logs` - 输出一个pod的容器日志.
```shell
// 从名称为<pod-name>的pod返回日志快照.
$ kubectl logs <pod-name>
// 从名称为<pod-name>的pod中获取日志流. 这个和Linux命令'tail -f'相似.
$ kubectl logs -f <pod-name>
```
## 下一步
开始使用[kubectl](/docs/user-guide/kubectl)命令。
+86 -2
View File
@@ -14,17 +14,18 @@ kubectl 可以操控 Kubernetes 集群。
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Find more information at: /docs/reference/kubectl/overview/
-->
### 简介
kubectl 可以操控 Kubernetes 集群。
获取更多信息,请访问:https://kubernetes.io/docs/reference/kubectl/overview/
获取更多信息,请访问:[kubectl 概述](/docs/reference/kubectl/overview/)
```
kubectl [flags]
```
<!--
### Options
@@ -55,6 +56,7 @@ kubectl [flags]
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```
-->
### 选项
```
--alsologtostderr 同时输出日志到标准错误控制台和文件
@@ -177,3 +179,85 @@ kubectl [flags]
######2018年6月16日,通过spf13/cobra自动生成
<!-- * [kubectl alpha](kubectl_alpha.md) - Commands for features in alpha -->
* [kubectl alpha](kubectl_alpha.md) - kubectl alpha 功能
<!-- * [kubectl annotate](kubectl_annotate.md) - Update the annotations on a resource -->
* [kubectl annotate](kubectl_annotate.md) - 更新资源所关联的注解
<!-- * [kubectl api-resources](kubectl_api-resources.md) - Print the supported API resources on the server -->
* [kubectl api-resources](kubectl_api-resources.md) - 打印服务器上所支持的 API 资源
<!-- * [kubectl api-versions](kubectl_api-versions.md) - Print the supported API versions on the server, in the form of "group/version" -->
* [kubectl api-versions](kubectl_api-versions.md) - 以“组/版本”的格式输出服务端支持的 API 版本
<!-- * [kubectl apply](kubectl_apply.md) - Apply a configuration to a resource by filename or stdin -->
* [kubectl apply](kubectl_apply.md) - 基于文件名或标准输入,将新的配置应用到资源上
<!-- * [kubectl attach](kubectl_attach.md) - Attach to a running container -->
* [kubectl attach](kubectl_attach.md) - 连接到一个正在运行的容器
<!-- * [kubectl auth](kubectl_auth.md) - Inspect authorization -->
* [kubectl auth](kubectl_auth.md) - 检视授权信息
<!-- * [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a Deployment, ReplicaSet, or ReplicationController -->
* [kubectl autoscale](kubectl_autoscale.md) - 对一个资源对象( Deployment、ReplicaSet 或 ReplicationController )进行扩缩
<!-- * [kubectl certificate](kubectl_certificate.md) - Modify certificate resources. -->
* [kubectl certificate](kubectl_certificate.md) - 修改证书资源
<!-- * [kubectl cluster-info](kubectl_cluster-info.md) - Display cluster info -->
* [kubectl cluster-info](kubectl_cluster-info.md) - 显示集群信息
<!-- * [kubectl completion](kubectl_completion.md) - Output shell completion code for the specified shell (bash or zsh) -->
* [kubectl completion](kubectl_completion.md) - 根据已经给出的 Shellbash 或 zsh),输出 Shell 补全后的代码
<!-- * [kubectl config](kubectl_config.md) - Modify kubeconfig files -->
* [kubectl config](kubectl_config.md) - 修改 kubeconfig 配置文件
<!-- * [kubectl convert](kubectl_convert.md) - Convert config files between different API versions -->
* [kubectl convert](kubectl_convert.md) - 在不同的 API 版本之间转换配置文件
<!-- * [kubectl cordon](kubectl_cordon.md) - Mark node as unschedulable -->
* [kubectl cordon](kubectl_cordon.md) - 标记节点为不可调度的
<!-- * [kubectl cp](kubectl_cp.md) - Copy files and directories to and from containers. -->
* [kubectl cp](kubectl_cp.md) - 将文件和路径拷入/拷出容器。
<!-- * [kubectl create](kubectl_create.md) - Create a resource from a file or from stdin. -->
* [kubectl create](kubectl_create.md) - 通过文件或标准输入来创建资源
<!-- * [kubectl delete](kubectl_delete.md) - Delete resources by filenames, stdin, resources and names, or by resources and label selector -->
* [kubectl delete](kubectl_delete.md) - 通过文件名、标准输入、资源和名字删除资源,或者通过资源和标签选择器来删除资源
<!-- * [kubectl describe](kubectl_describe.md) - Show details of a specific resource or group of resources -->
* [kubectl describe](kubectl_describe.md) - 显示某个资源或某组资源的详细信息
<!-- * [kubectl drain](kubectl_drain.md) - Drain node in preparation for maintenance -->
* [kubectl drain](kubectl_drain.md) - 腾空节点,准备维护
<!-- * [kubectl edit](kubectl_edit.md) - Edit a resource on the server -->
* [kubectl edit](kubectl_edit.md) - 修改服务器上的某资源
<!-- * [kubectl exec](kubectl_exec.md) - Execute a command in a container -->
* [kubectl exec](kubectl_exec.md) - 在容器中执行命令
<!-- * [kubectl explain](kubectl_explain.md) - Documentation of resources -->
* [kubectl explain](kubectl_explain.md) - 显示资源说明
<!-- * [kubectl expose](kubectl_expose.md) - Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service -->
* [kubectl expose](kubectl_expose.md) - 给定副本控制器、服务、Deployment 或 Pod,将其暴露为新的 kubernetes Service
<!-- * [kubectl get](kubectl_get.md) - Display one or many resources -->
* [kubectl get](kubectl_get.md) - 显示一个或者多个资源信息
<!-- * [kubectl label](kubectl_label.md) - Update the labels on a resource -->
* [kubectl label](kubectl_label.md) - 更新资源的标签
<!-- * [kubectl logs](kubectl_logs.md) - Print the logs for a container in a pod -->
* [kubectl logs](kubectl_logs.md) - 输出 pod 中某容器的日志
<!-- * [kubectl options](kubectl_options.md) - Print the list of flags inherited by all commands -->
* [kubectl options](kubectl_options.md) - 打印所有命令都支持的共有参数列表
<!-- * [kubectl patch](kubectl_patch.md) - Update field(s) of a resource using strategic merge patch -->
* [kubectl patch](kubectl_patch.md) - 基于策略性合并修补(Stategic Merge Patch)规则更新某资源中的字段
<!-- * [kubectl plugin](kubectl_plugin.md) - Runs a command-line plugin -->
* [kubectl plugin](kubectl_plugin.md) - 运行命令行插件
<!-- * [kubectl port-forward](kubectl_port-forward.md) - Forward one or more local ports to a pod -->
* [kubectl port-forward](kubectl_port-forward.md) - 将一个或者多个本地端口转发到 pod
<!-- * [kubectl proxy](kubectl_proxy.md) - Run a proxy to the Kubernetes API server -->
* [kubectl proxy](kubectl_proxy.md) - 运行一个 kubernetes API 服务器代理
<!-- * [kubectl replace](kubectl_replace.md) - Replace a resource by filename or stdin -->
* [kubectl replace](kubectl_replace.md) - 基于文件名或标准输入替换资源
<!-- * [kubectl rollout](kubectl_rollout.md) - Manage the rollout of a resource -->
* [kubectl rollout](kubectl_rollout.md) - 管理资源的上线
<!-- * [kubectl run](kubectl_run.md) - Run a particular image on the cluster -->
* [kubectl run](kubectl_run.md) - 在集群中使用指定镜像启动容器
<!-- * [kubectl scale](kubectl_scale.md) - Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job -->
* [kubectl scale](kubectl_scale.md) - 为一个 Deployment、ReplicaSet、ReplicationController 或 Job 设置一个新的规模尺寸值
<!-- * [kubectl set](kubectl_set.md) - Set specific features on objects -->
* [kubectl set](kubectl_set.md) - 在资源对象设置特定的功能
<!-- * [kubectl taint](kubectl_taint.md) - Update the taints on one or more nodes -->
* [kubectl taint](kubectl_taint.md) - 在一个或者多个节点上更新污点配置
<!-- * [kubectl top](kubectl_top.md) - Display Resource (CPU/Memory/Storage) usage. -->
* [kubectl top](kubectl_top.md) - 显示资源(CPU /内存/存储)使用率
<!-- * [kubectl uncordon](kubectl_uncordon.md) - Mark node as schedulable -->
* [kubectl uncordon](kubectl_uncordon.md) - 标记节点为可调度的
<!-- * [kubectl version](kubectl_version.md) - Print the client and server version information -->
* [kubectl version](kubectl_version.md) - 打印客户端和服务器的版本信息
<!-- * [kubectl wait](kubectl_wait.md) - Experimental: Wait for one condition on one or many resources -->
* [kubectl wait](kubectl_wait.md) - 实验性:等待一个或多个资源达到某种状态
@@ -0,0 +1,921 @@
---
reviewers:
- hw-qiaolei
title: kubectl 概述
content_template: templates/concept
weight: 20
card:
name: reference
weight: 20
---
<!--
---
reviewers:
- bgrant0607
- hw-qiaolei
title: Overview of kubectl
content_template: templates/concept
weight: 20
card:
name: reference
weight: 20
---
-->
{{% capture overview %}}
<!--
Kubectl is a command line interface for running commands against Kubernetes clusters. `kubectl` looks for a file named config in the $HOME/.kube directory. You can specify other [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) files by setting the KUBECONFIG environment variable or by setting the [`--kubeconfig`](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) flag.
-->
Kubectl 是一个命令行接口,用于对 Kubernetes 集群运行命令。`kubectl` 在 $HOME/.kube 目录中寻找一个名为 config 的文件。您可以通过设置环境变量 KUBECONFIG 或设置 [`--kubeconfig`](/docs/concepts/configuration/organize-cluster-access-kubeconfig/) 参数指定其它 [kubeconfig](/docs/concepts/configuration/organize-cluster-access-kubeconfig/) 文件。
<!--
This overview covers `kubectl` syntax, describes the command operations, and provides common examples. For details about each command, including all the supported flags and subcommands, see the [kubectl](/docs/reference/generated/kubectl/kubectl-commands/) reference documentation. For installation instructions see [installing kubectl](/docs/tasks/kubectl/install/).
-->
本文概述了 `kubectl` 语法和命令操作描述,并提供了常见的示例。有关每个命令的详细信息,包括所有受支持的参数和子命令,请参阅 [kubectl](/docs/reference/generated/kubectl/kubectl-commands/) 参考文档。有关安装说明,请参见 [安装 kubectl](/docs/tasks/kubectl/install/) 。
{{% /capture %}}
{{% capture body %}}
<!--
## Syntax
-->
## 语法
<!--
Use the following syntax to run `kubectl` commands from your terminal window:
-->
使用以下语法 `kubectl` 从终端窗口运行命令:
```shell
kubectl [command] [TYPE] [NAME] [flags]
```
<!--
where `command`, `TYPE`, `NAME`, and `flags` are:
-->
其中 `command``TYPE``NAME``flags` 分别是:
<!--
* `command`: Specifies the operation that you want to perform on one or more resources, for example `create`, `get`, `describe`, `delete`.
* `TYPE`: Specifies the [resource type](#resource-types). Resource types are case-insensitive and you can specify the singular, plural, or abbreviated forms. For example, the following commands produce the same output:
-->
* `command`:指定要对一个或多个资源执行的操作,例如 `create``get``describe``delete`
* `TYPE`:指定[资源类型](#resource-types)。资源类型不区分大小写,可以指定单数、复数或缩写形式。例如,以下命令输出相同的结果:
```shell
kubectl get pod pod1
kubectl get pods pod1
kubectl get po pod1
```
<!--
* `NAME`: Specifies the name of the resource. Names are case-sensitive. If the name is omitted, details for all resources are displayed, for example `kubectl get pods`.
When performing an operation on multiple resources, you can specify each resource by type and name or specify one or more files:
-->
* `NAME`:指定资源的名称。名称区分大小写。如果省略名称,则显示所有资源的详细信息 `kubectl get pods`。
在对多个资源执行操作时,您可以按类型和名称指定每个资源,或指定一个或多个文件:
<!--
* To specify resources by type and name:
* To group resources if they are all the same type: `TYPE1 name1 name2 name<#>`.<br/>
Example: `kubectl get pod example-pod1 example-pod2`
* To specify multiple resource types individually: `TYPE1/name1 TYPE1/name2 TYPE2/name3 TYPE<#>/name<#>`.<br/>
Example: `kubectl get pod/example-pod1 replicationcontroller/example-rc1`
* To specify resources with one or more files: `-f file1 -f file2 -f file<#>`
* [Use YAML rather than JSON](/docs/concepts/configuration/overview/#general-config-tips) since YAML tends to be more user-friendly, especially for configuration files.<br/>
Example: `kubectl get pod -f ./pod.yaml`
* `flags`: Specifies optional flags. For example, you can use the `-s` or `--server` flags to specify the address and port of the Kubernetes API server.<br/>
-->
* 要按类型和名称指定资源:
* 要对所有类型相同的资源进行分组,请执行以下操作:`TYPE1 name1 name2 name<#>`。<br/>
例子:`kubectl get pod example-pod1 example-pod2`
* 分别指定多个资源类型:`TYPE1/name1 TYPE1/name2 TYPE2/name3 TYPE<#>/name<#>`。<br/>
例子:`kubectl get pod/example-pod1 replicationcontroller/example-rc1`
* 用一个或多个文件指定资源:`-f file1 -f file2 -f file<#>`
* [使用 YAML 而不是 JSON](/docs/concepts/configuration/overview/#general-config-tips) 因为 YAML 更容易使用,特别是用于配置文件时。<br/>
例子:`kubectl get pod -f ./pod.yaml`
* `flags`: 指定可选的参数。例如,可以使用 `-s` 或 `-server` 参数指定 Kubernetes API 服务器的地址和端口。<br/>
{{< caution >}}
<!--
Flags that you specify from the command line override default values and any corresponding environment variables.
-->
从命令行指定的参数会覆盖默认值和任何相应的环境变量。
{{< /caution >}}
<!--
If you need help, just run `kubectl help` from the terminal window.
-->
如果您需要帮助,只需从终端窗口运行 ` kubectl help ` 即可。
<!--
## Operations
-->
## 操作
<!--
The following table includes short descriptions and the general syntax for all of the `kubectl` operations:
-->
下表包含所有 kubectl 操作的简短描述和普通语法:
<!--
Operation | Syntax | Description
-------------------- | -------------------- | --------------------
`annotate` | `kubectl annotate (-f FILENAME \| TYPE NAME \| TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | Add or update the annotations of one or more resources.
`api-versions` | `kubectl api-versions [flags]` | List the API versions that are available.
`apply` | `kubectl apply -f FILENAME [flags]`| Apply a configuration change to a resource from a file or stdin.
`attach` | `kubectl attach POD -c CONTAINER [-i] [-t] [flags]` | Attach to a running container either to view the output stream or interact with the container (stdin).
`autoscale` | `kubectl autoscale (-f FILENAME \| TYPE NAME \| TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]` | Automatically scale the set of pods that are managed by a replication controller.
`cluster-info` | `kubectl cluster-info [flags]` | Display endpoint information about the master and services in the cluster.
`config` | `kubectl config SUBCOMMAND [flags]` | Modifies kubeconfig files. See the individual subcommands for details.
`create` | `kubectl create -f FILENAME [flags]` | Create one or more resources from a file or stdin.
`delete` | `kubectl delete (-f FILENAME \| TYPE [NAME \| /NAME \| -l label \| --all]) [flags]` | Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
`describe` | `kubectl describe (-f FILENAME \| TYPE [NAME_PREFIX \| /NAME \| -l label]) [flags]` | Display the detailed state of one or more resources.
`diff` | `kubectl diff -f FILENAME [flags]`| Diff file or stdin against live configuration (**BETA**)
`edit` | `kubectl edit (-f FILENAME \| TYPE NAME \| TYPE/NAME) [flags]` | Edit and update the definition of one or more resources on the server by using the default editor.
`exec` | `kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]` | Execute a command against a container in a pod.
`explain` | `kubectl explain [--recursive=false] [flags]` | Get documentation of various resources. For instance pods, nodes, services, etc.
`expose` | `kubectl expose (-f FILENAME \| TYPE NAME \| TYPE/NAME) [--port=port] [--protocol=TCP\|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] [flags]` | Expose a replication controller, service, or pod as a new Kubernetes service.
`get` | `kubectl get (-f FILENAME \| TYPE [NAME \| /NAME \| -l label]) [--watch] [--sort-by=FIELD] [[-o \| --output]=OUTPUT_FORMAT] [flags]` | List one or more resources.
`label` | `kubectl label (-f FILENAME \| TYPE NAME \| TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | Add or update the labels of one or more resources.
`logs` | `kubectl logs POD [-c CONTAINER] [--follow] [flags]` | Print the logs for a container in a pod.
`patch` | `kubectl patch (-f FILENAME \| TYPE NAME \| TYPE/NAME) --patch PATCH [flags]` | Update one or more fields of a resource by using the strategic merge patch process.
`port-forward` | `kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]` | Forward one or more local ports to a pod.
`proxy` | `kubectl proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix] [flags]` | Run a proxy to the Kubernetes API server.
`replace` | `kubectl replace -f FILENAME` | Replace a resource from a file or stdin.
`rolling-update` | `kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE \| -f NEW_CONTROLLER_SPEC) [flags]` | Perform a rolling update by gradually replacing the specified replication controller and its pods.
`run` | `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [flags]` | Run a specified image on the cluster.
`scale` | `kubectl scale (-f FILENAME \| TYPE NAME \| TYPE/NAME) --replicas=COUNT [--resource-version=version] [--current-replicas=count] [flags]` | Update the size of the specified replication controller.
`stop` | `kubectl stop` | Deprecated: Instead, see `kubectl delete`.
`version` | `kubectl version [--client] [flags]` | Display the Kubernetes version running on the client and server.
-->
操作 | 语法 | 描述
-------------------- | -------------------- | --------------------
`annotate` | `kubectl annotate (-f FILENAME \| TYPE NAME \| TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | 添加或更新一个或多个资源的注解。
`api-versions` | `kubectl api-versions [flags]` | 列出可用的 API 版本。
`apply` | `kubectl apply -f FILENAME [flags]`| 从文件或 stdin 对资源应用配置更改。
`attach` | `kubectl attach POD -c CONTAINER [-i] [-t] [flags]` | 附加到正在运行的容器,查看输出流或与容器(stdin)交互。
`autoscale` | `kubectl autoscale (-f FILENAME \| TYPE NAME \| TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]` | 自动伸缩由副本控制器管理的一组 pod。
`cluster-info` | `kubectl cluster-info [flags]` | 显示有关集群中主服务器和服务的端口信息。
`config` | `kubectl config SUBCOMMAND [flags]` | 修改 kubeconfig 文件。有关详细信息,请参阅各个子命令。
`create` | `kubectl create -f FILENAME [flags]` | 从文件或 stdin 创建一个或多个资源。
`delete` | `kubectl delete (-f FILENAME \| TYPE [NAME \| /NAME \| -l label \| --all]) [flags]` | 从文件、标准输入或指定标签选择器、名称、资源选择器或资源中删除资源。
`describe` | `kubectl describe (-f FILENAME \| TYPE [NAME_PREFIX \| /NAME \| -l label]) [flags]` | 显示一个或多个资源的详细状态。
`diff` | `kubectl diff -f FILENAME [flags]`| 将 live 配置和文件或标准输入做对比 (**BETA**)
`edit` | `kubectl edit (-f FILENAME \| TYPE NAME \| TYPE/NAME) [flags]` | 使用默认编辑器编辑和更新服务器上一个或多个资源的定义。
`exec` | `kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]` | 对 pod 中的容器执行命令。
`explain` | `kubectl explain [--recursive=false] [flags]` | 获取多种资源的文档。例如 pod, node, service 等。
`expose` | `kubectl expose (-f FILENAME \| TYPE NAME \| TYPE/NAME) [--port=port] [--protocol=TCP\|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] [flags]` | 将副本控制器、服务或 pod 作为新的 Kubernetes 服务暴露。
`get` | `kubectl get (-f FILENAME \| TYPE [NAME \| /NAME \| -l label]) [--watch] [--sort-by=FIELD] [[-o \| --output]=OUTPUT_FORMAT] [flags]` | 列出一个或多个资源。
`label` | `kubectl label (-f FILENAME \| TYPE NAME \| TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]` | 添加或更新一个或多个资源的标签。
`logs` | `kubectl logs POD [-c CONTAINER] [--follow] [flags]` | 在 pod 中打印容器的日志。
`patch` | `kubectl patch (-f FILENAME \| TYPE NAME \| TYPE/NAME) --patch PATCH [flags]` | 使用策略合并 patch 程序更新资源的一个或多个字段。
`port-forward` | `kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]` | 将一个或多个本地端口转发到一个 pod。
`proxy` | `kubectl proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix] [flags]` | 运行 Kubernetes API 服务器的代理。
`replace` | `kubectl replace -f FILENAME` | 从文件或标准输入中替换资源。
`rolling-update` | `kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE \| -f NEW_CONTROLLER_SPEC) [flags]` | 通过逐步替换指定的副本控制器及其 pod 来执行滚动更新。
`run` | `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [flags]` | 在集群上运行指定的镜像。
`scale` | `kubectl scale (-f FILENAME \| TYPE NAME \| TYPE/NAME) --replicas=COUNT [--resource-version=version] [--current-replicas=count] [flags]` | 更新指定副本控制器的大小。
`stop` | `kubectl stop` | 不推荐:相反,请参阅 kubectl delete。
`version` | `kubectl version [--client] [flags]` | 显示运行在客户端和服务器上的 Kubernetes 版本。
<!--
Remember: For more about command operations, see the [kubectl](/docs/user-guide/kubectl/) reference documentation.
-->
记住:有关命令操作的更多信息,请参阅 [kubectl](/docs/user-guide/kubectl/) 参考文档。
<!--
## Resource types
-->
## 资源类型
<!--
The following table includes a list of all the supported resource types and their abbreviated aliases:
-->
下表列出所有受支持的资源类型及其缩写别名:
<!--
(This output can be retrieved from `kubectl api-resources`, and is accurate as of Kubernetes 1.13.3.)
-->
(以下输出可以通过 `kubectl api-resources` 获取,内容以 Kubernetes 1.13.3 版本为准。)
<!--
| Resource Name | Short Names | API Group | Namespaced | Resource Kind |
|---|---|---|---|---|
| `componentstatuses` | `cs` | | false | ComponentStatus |
| `configmaps` | `cm` | | true | ConfigMap |
| `endpoints` | `ep` | | true | Endpoints |
| `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 |
| `localsubjectaccessreviews` | | authorization.k8s.io | true | LocalSubjectAccessReview |
| `selfsubjectaccessreviews` | | authorization.k8s.io | false | SelfSubjectAccessReview |
| `selfsubjectrulesreviews` | | authorization.k8s.io | false | SelfSubjectRulesReview |
| `subjectaccessreviews` | | authorization.k8s.io | false | SubjectAccessReview |
| `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 |
| `ingresses` | `ing` | extensions | true | Ingress |
| `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 |
-->
| 资源名 | 缩写名 | API 分组 | 按命名空间 | 资源类型 |
|---|---|---|---|---|
| `componentstatuses` | `cs` | | false | ComponentStatus |
| `configmaps` | `cm` | | true | ConfigMap |
| `endpoints` | `ep` | | true | Endpoints |
| `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 |
| `localsubjectaccessreviews` | | authorization.k8s.io | true | LocalSubjectAccessReview |
| `selfsubjectaccessreviews` | | authorization.k8s.io | false | SelfSubjectAccessReview |
| `selfsubjectrulesreviews` | | authorization.k8s.io | false | SelfSubjectRulesReview |
| `subjectaccessreviews` | | authorization.k8s.io | false | SubjectAccessReview |
| `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 |
| `ingresses` | `ing` | extensions | true | Ingress |
| `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 |
<!--
## Output options
-->
## 输出选项
<!--
Use the following sections for information about how you can format or sort the output of certain commands. For details about which commands support the various output options, see the [kubectl](/docs/user-guide/kubectl/) reference documentation.
-->
有关如何格式化或排序某些命令的输出的信息,请使用以下部分。有关哪些命令支持各种输出选项的详细信息,请参阅[kubectl](/docs/user-guide/kubectl/) 参考文档。
<!--
### Formatting output
-->
### 格式化输出
<!--
The default output format for all `kubectl` commands is the human readable plain-text format. To output details to your terminal window in a specific format, you can add either the `-o` or `--output` flags to a supported `kubectl` command.
-->
所有 `kubectl` 命令的默认输出格式都是人类可读的纯文本格式。要以特定格式向终端窗口输出详细信息,可以将 `-o` 或 `--output` 参数添加到受支持的 `kubectl` 命令中。
<!--
#### Syntax
-->
#### 语法
```shell
kubectl [command] [TYPE] [NAME] -o=<output_format>
```
<!--
Depending on the `kubectl` operation, the following output formats are supported:
-->
根据 `kubectl` 操作,支持以下输出格式:
<!--
Output format | Description
--------------| -----------
`-o custom-columns=<spec>` | Print a table using a comma separated list of [custom columns](#custom-columns).
`-o custom-columns-file=<filename>` | Print a table using the [custom columns](#custom-columns) template in the `<filename>` file.
`-o json` | Output a JSON formatted API object.
`-o jsonpath=<template>` | Print the fields defined in a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
`-o jsonpath-file=<filename>` | Print the fields defined by the [jsonpath](/docs/reference/kubectl/jsonpath/) expression in the `<filename>` file.
`-o name` | Print only the resource name and nothing else.
`-o wide` | Output in the plain-text format with any additional information. For pods, the node name is included.
`-o yaml` | Output a YAML formatted API object.
-->
Output format | Description
--------------| -----------
`-o custom-columns=<spec>` | 使用逗号分隔的[自定义列](#custom-columns)列表打印表。
`-o custom-columns-file=<filename>` | 使用 `<filename>` 文件中的[自定义列](#custom-columns)模板打印表。
`-o json` | 输出 JSON 格式的 API 对象
`-o jsonpath=<template>` | 打印 [jsonpath](/docs/reference/kubectl/jsonpath/) 表达式定义的字段
`-o jsonpath-file=<filename>` | 打印 `<filename>` 文件中 [jsonpath](/docs/reference/kubectl/jsonpath/) 表达式定义的字段。
`-o name` | 仅打印资源名称而不打印任何其他内容。
`-o wide` | 以纯文本格式输出,包含任何附加信息。对于 pod 包含节点名。
`-o yaml` | 输出 YAML 格式的 API 对象。
<!--
##### Example
-->
##### 示例
<!--
In this example, the following command outputs the details for a single pod as a YAML formatted object:
-->
在此示例中,以下命令将单个 pod 的详细信息输出为 YAML 格式的对象:
```shell
kubectl get pod web-pod-13je7 -o yaml
```
<!--
Remember: See the [kubectl](/docs/user-guide/kubectl/) reference documentation for details about which output format is supported by each command.
-->
请记住:有关每个命令支持哪种输出格式的详细信息,请参阅 [kubectl](/docs/user-guide/kubectl/) 参考文档。
<!--
#### Custom columns
-->
#### 自定义列
<!--
To define custom columns and output only the details that you want into a table, you can use the `custom-columns` option. You can choose to define the custom columns inline or use a template file: `-o=custom-columns=<spec>` or `-o=custom-columns-file=<filename>`.
-->
要定义自定义列并仅将所需的详细信息输出到表中,可以使用该 custom-columns 选项。您可以选择内联定义自定义列或使用模板文件:`-o=custom-columns=<spec>` 或 `-o=custom-columns-file=<filename>`。
<!--
##### Examples
-->
##### 示例
<!--
Inline:
-->
内联:
```shell
$ kubectl get pods <pod-name> -o custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion
```
<!--
Template file:
-->
模板文件:
```shell
kubectl get pods <pod-name> -o custom-columns-file=template.txt
```
<!--
where the `template.txt` file contains:
-->
其中,`template.txt` 文件包含:
```
NAME RSRC
metadata.name metadata.resourceVersion
```
<!--
The result of running either command is:
-->
运行任何一个命令的结果是:
```shell
NAME RSRC
submit-queue 610995
```
<!--
#### Server-side columns
-->
#### Server-side 列
<!--
`kubectl` supports receiving specific column information from the server about objects.
This means that for any given resource, the server will return columns and rows relevant to that resource, for the client to print.
This allows for consistent human-readable output across clients used against the same cluster, by having the server encapsulate the details of printing.
-->
`kubectl` 支持从服务器接收关于对象的特定列信息。
这意味着对于任何给定的资源,服务器将返回与该资源相关的列和行,以便客户端打印。
通过让服务器封装打印的细节,这允许在针对同一集群使用的客户端之间提供一致的人类可读输出。
<!--
This feature is enabled by default in `kubectl` 1.11 and higher. To disable it, add the
`--server-print=false` flag to the `kubectl get` command.
-->
默认情况下,此功能在 `kubectl` 1.11 及更高版本中启用。要禁用它,请将该 `--server-print=false` 参数添加到 `kubectl get` 命令中。
<!--
##### Examples
-->
##### 例子:
<!--
To print information about the status of a pod, use a command like the following:
-->
要打印有关 pod 状态的信息,请使用如下命令:
```shell
kubectl get pods <pod-name> --server-print=false
```
<!--
Output looks like this:
-->
输出如下:
```shell
NAME READY STATUS RESTARTS AGE
pod-name 1/1 Running 0 1m
```
<!--
### Sorting list objects
-->
### 排序列表对象
<!--
To output objects to a sorted list in your terminal window, you can add the `--sort-by` flag to a supported `kubectl` command. Sort your objects by specifying any numeric or string field with the `--sort-by` flag. To specify a field, use a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
-->
要将对象排序后输出到终端窗口,可以将 `--sort-by` 参数添加到支持的 `kubectl` 命令。通过使用 `--sort-by` 参数指定任何数字或字符串字段来对对象进行排序。要指定字段,请使用 [jsonpath](/docs/reference/kubectl/jsonpath/) 表达式。
<!--
#### Syntax
-->
#### 语法
```shell
kubectl [command] [TYPE] [NAME] --sort-by=<jsonpath_exp>
```
<!--
##### Example
-->
##### 示例
<!--
To print a list of pods sorted by name, you run:
-->
要打印按名称排序的 pod 列表,请运行:
```shell
$ kubectl get pods --sort-by=.metadata.name
```
<!--
## Examples: Common operations
-->
## 示例:常用操作
<!--
Use the following set of examples to help you familiarize yourself with running the commonly used `kubectl` operations:
-->
使用以下示例集来帮助您熟悉运行常用 kubectl 操作:
<!--
`kubectl apply` - Apply or Update a resource from a file or stdin.
-->
`kubectl apply` - 以文件或标准输入为准应用或更新资源。
<!--
```shell
# Create a service using the definition in example-service.yaml.
kubectl apply -f example-service.yaml
# Create a replication controller using the definition in example-controller.yaml.
kubectl apply -f example-controller.yaml
# Create the objects that are defined in any .yaml, .yml, or .json file within the <directory> directory.
kubectl apply -f <directory>
```
-->
```shell
# 使用 example-service.yaml 中的定义创建服务。
kubectl apply -f example-service.yaml
# 使用 example-controller.yaml 中的定义创建 replication controller。
kubectl apply -f example-controller.yaml
# 使用 <directory> 路径下的任意 .yaml, .yml, 或 .json 文件 创建对象。
kubectl apply -f <directory>
```
<!--
`kubectl get` - List one or more resources.
-->
`kubectl get` - 列出一个或多个资源。
<!--
# List all pods in plain-text output format.
# List all pods in plain-text output format and include additional information (such as node name).
# List the replication controller with the specified name in plain-text output format. Tip: You can shorten and replace the 'replicationcontroller' resource type with the alias 'rc'.
# List all replication controllers and services together in plain-text output format.
# List all daemon sets, including uninitialized ones, in plain-text output format.
# List all pods running on node server01
-->
```shell
# 以纯文本输出格式列出所有 pod。
kubectl get pods
# 以纯文本输出格式列出所有 pod,并包含附加信息(如节点名)。
kubectl get pods -o wide
# 以纯文本输出格式列出具有指定名称的副本控制器。提示:您可以使用别名 'rc' 缩短和替换 'replicationcontroller' 资源类型。
kubectl get replicationcontroller <rc-name>
# 以纯文本输出格式列出所有副本控制器和服务。
kubectl get rc,services
# 以纯文本输出格式列出所有守护程序集,包括未初始化的守护程序集。
kubectl get ds --include-uninitialized
# 列出在节点 server01 上运行的所有 pod
kubectl get pods --field-selector=spec.nodeName=server01
```
<!--
`kubectl describe` - Display detailed state of one or more resources, including the uninitialized ones by default.
-->
`kubectl describe` - 显示一个或多个资源的详细状态,默认情况下包括未初始化的资源。
<!--
# Display the details of the node with name <node-name>.
# Display the details of the pod with name <pod-name>.
# Display the details of all the pods that are managed by the replication controller named <rc-name>.
# Remember: Any pods that are created by the replication controller get prefixed with the name of the replication controller.
# Describe all pods, not including uninitialized ones
-->
```shell
# 显示名称为 <node-name> 的节点的详细信息。
kubectl describe nodes <node-name>
# 显示名为 <pod-name> 的 pod 的详细信息。
kubectl describe pods/<pod-name>
# 显示由名为 <rc-name> 的副本控制器管理的所有 pod 的详细信息。
# 记住:副本控制器创建的任何 pod 都以复制控制器的名称为前缀。
kubectl describe pods <rc-name>
# 描述所有的 pod,不包括未初始化的 pod
kubectl describe pods --include-uninitialized=false
```
{{< note >}}
<!--
The `kubectl get` command is usually used for retrieving one or more
resources of the same resource type. It features a rich set of flags that allows
you to customize the output format using the `-o` or `--output` flag, for example.
You can specify the `-w` or `--watch` flag to start watching updates to a particular
object. The `kubectl describe` command is more focused on describing the many
related aspects of a specified resource. It may invoke several API calls to the
API server to build a view for the user. For example, the `kubectl describe node`
command retrieves not only the information about the node, but also a summary of
the pods running on it, the events generated for the node etc.
-->
`kubectl get` 命令通常用于检索同一资源类型的一个或多个资源。
它具有丰富的参数,允许您使用 `-o` 或 `--output` 参数自定义输出格式。您可以指定 `-w` 或 `--watch` 参数以开始观察特定对象的更新。
`kubectl describe` 命令更侧重于描述指定资源的许多相关方面。它可以调用对 `API 服务器` 的多个 API 调用来为用户构建视图。
例如,该 `kubectl describe node` 命令不仅检索有关节点的信息,还检索在其上运行的 pod 的摘要,为节点生成的事件等。
{{< /note >}}
<!--
`kubectl delete` - Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
-->
`kubectl delete` - 从文件、stdin 或指定标签选择器、名称、资源选择器或资源中删除资源。
<!--
# Delete a pod using the type and name specified in the pod.yaml file.
# Delete all the pods and services that have the label name=<label-name>.
# Delete all the pods and services that have the label name=<label-name>, including uninitialized ones.
// Delete all pods, including uninitialized ones.
-->
```shell
# 使用 pod.yaml 文件中指定的类型和名称删除 pod。
kubectl delete -f pod.yaml
# 删除标签名= <label-name> 的所有 pod 和服务。
kubectl delete pods,services -l name=<label-name>
# 删除所有具有标签名称= <label-name> 的 pod 和服务,包括未初始化的那些。
kubectl delete pods,services -l name=<label-name> --include-uninitialized
# 删除所有 pod,包括未初始化的 pod。
kubectl delete pods --all
```
<!--
`kubectl exec` - Execute a command against a container in a pod.
-->
`kubectl exec` - 对 pod 中的容器执行命令。
<!--
# Get output from running 'date' from pod <pod-name>. By default, output is from the first container.
# Get output from running 'date' in container <container-name> of pod <pod-name>.
# Get an interactive TTY and run /bin/bash from pod <pod-name>. By default, output is from the first container.
-->
```shell
# 从 pod <pod-name> 中获取运行 'date' 的输出。默认情况下,输出来自第一个容器。
kubectl exec <pod-name> date
# 运行输出 'date' 获取在容器的 <container-name> 中 pod <pod-name> 的输出。
kubectl exec <pod-name> -c <container-name> date
# 获取一个交互 TTY 并运行 /bin/bash <pod-name >。默认情况下,输出来自第一个容器。
kubectl exec -ti <pod-name> /bin/bash
```
<!--
`kubectl logs` - Print the logs for a container in a pod.
-->
`kubectl logs` - 打印 Pod 中容器的日志。
<!--
# Return a snapshot of the logs from pod <pod-name>.
# Start streaming the logs from pod <pod-name>. This is similar to the 'tail -f' Linux command.
-->
```shell
# 从 pod 返回日志快照。
kubectl logs <pod-name>
# 从 pod <pod-name> 开始流式传输日志。这类似于 'tail -f' Linux 命令。
kubectl logs -f <pod-name>
```
<!--
## Examples: Creating and using plugins
-->
## 示例:创建和使用插件
<!--
Use the following set of examples to help you familiarize yourself with writing and using `kubectl` plugins:
-->
使用以下示例来帮助您熟悉编写和使用 `kubectl` 插件:
<!--
```shell
# create a simple plugin in any language and name the resulting executable file
# so that it begins with the prefix "kubectl-"
cat ./kubectl-hello
#!/bin/bash
# this plugin prints the words "hello world"
echo "hello world"
# with our plugin written, let's make it executable
sudo chmod +x ./kubectl-hello
# and move it to a location in our PATH
sudo mv ./kubectl-hello /usr/local/bin
# we have now created and "installed" a kubectl plugin.
# we can begin using our plugin by invoking it from kubectl as if it were a regular command
kubectl hello
```
-->
```shell
# 用任何语言创建一个简单的插件,并为生成的可执行文件命名
# 以前缀 "kubectl-" 开始
cat ./kubectl-hello
#!/bin/bash
# 这个插件打印单词 "hello world"
echo "hello world"
# 我们的插件写好了,让我们把它变成可执行的
sudo chmod +x ./kubectl-hello
# 并将其移动到路径中的某个位置
sudo mv ./kubectl-hello /usr/local/bin
# 我们现在已经创建并"安装"了一个 kubectl 插件。
# 我们可以开始使用我们的插件,从 kubectl 调用它,就像它是一个常规命令一样
kubectl hello
```
```
hello world
```
<!--
```
# we can "uninstall" a plugin, by simply removing it from our PATH
sudo rm /usr/local/bin/kubectl-hello
```
-->
```
# 我们可以"卸载"一个插件,只需从我们的路径中删除它
sudo rm /usr/local/bin/kubectl-hello
```
<!--
In order to view all of the plugins that are available to `kubectl`, we can use
the `kubectl plugin list` subcommand:
-->
为了查看可用的所有 `kubectl` 插件,我们可以使用 `kubectl plugin list` 子命令:
```shell
kubectl plugin list
```
<!--
```
The following kubectl-compatible plugins are available:
/usr/local/bin/kubectl-hello
/usr/local/bin/kubectl-foo
/usr/local/bin/kubectl-bar
```
-->
```
以下 kubectl-适配 的插件是可用的:
/usr/local/bin/kubectl-hello
/usr/local/bin/kubectl-foo
/usr/local/bin/kubectl-bar
```
<!--
```
# this command can also warn us about plugins that are
# not executable, or that are overshadowed by other
# plugins, for example
sudo chmod -x /usr/local/bin/kubectl-foo
kubectl plugin list
```
-->
```
# 这个指令也可以警告我们哪些插件
# 被运行,或是被其它插件覆盖了
# 例如
sudo chmod -x /usr/local/bin/kubectl-foo
kubectl plugin list
```
<!--
```
The following kubectl-compatible plugins are available:
/usr/local/bin/kubectl-hello
/usr/local/bin/kubectl-foo
- warning: /usr/local/bin/kubectl-foo identified as a plugin, but it is not executable
/usr/local/bin/kubectl-bar
error: one plugin warning was found
```
-->
```
以下 kubectl-适配 的插件是可用的:
/usr/local/bin/kubectl-hello
/usr/local/bin/kubectl-foo
- 警告: /usr/local/bin/kubectl-foo 被识别为一个插件,但是它并不可以执行
/usr/local/bin/kubectl-bar
错误: 发现了一个插件警告
```
<!--
We can think of plugins as a means to build more complex functionality on top
of the existing kubectl commands:
-->
我们可以将插件视为在现有 kubectl 命令之上构建更复杂功能的一种方法:
<!--
```shell
cat ./kubectl-whoami
#!/bin/bash
# this plugin makes use of the `kubectl config` command in order to output
# information about the current user, based on the currently selected context
kubectl config view --template='{{ range .contexts }}{{ if eq .name "'$(kubectl config current-context)'" }}Current user: {{ .context.user }}{{ end }}{{ end }}'
```
-->
```shell
cat ./kubectl-whoami
#!/bin/bash
# 这个插件借用 `kubectl config` 指令来输出
# 当前用户的信息,基于当前指定的 context
kubectl config view --template='{{ range .contexts }}{{ if eq .name "'$(kubectl config current-context)'" }}Current user: {{ .context.user }}{{ end }}{{ end }}'
```
<!--
Running the above plugin gives us an output containing the user for the currently selected
context in our KUBECONFIG file:
-->
运行上面的插件为我们提供了一个输出,其中包含我们 KUBECONFIG 文件中当前所选定上下文对应的用户:
<!--
```shell
# make the file executable
sudo chmod +x ./kubectl-whoami
# and move it into our PATH
sudo mv ./kubectl-whoami /usr/local/bin
kubectl whoami
Current user: plugins-user
```
-->
```shell
# 使文件成为可执行的
sudo chmod +x ./kubectl-whoami
# 然后移动到我们的路径中
sudo mv ./kubectl-whoami /usr/local/bin
kubectl whoami
Current user: plugins-user
```
<!--
To find out more about plugins, take a look at the [example cli plugin](https://github.com/kubernetes/sample-cli-plugin).
-->
要了解关于插件的更多信息,请查看[示例 cli 插件](https://github.com/kubernetes/sample-cli-plugin)。
{{% /capture %}}
{{% capture whatsnext %}}
<!--
Start using the [kubectl](/docs/reference/generated/kubectl/kubectl-commands/) commands.
-->
开始使用 [kubectl](/docs/reference/generated/kubectl/kubectl-commands/) 命令。
{{% /capture %}}