ZH-trans: merge release1.16-temporary to master (#18217)
* 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 * Update the conflict and merge the two commits * add nginx-deployment.yaml file 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: zhangx501 <zhang0000xun@gmail.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: 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:
committed by
Kubernetes Prow Robot
parent
9135bdbe6d
commit
b8b2cc7c74
@@ -1,12 +1,10 @@
|
||||
<!--
|
||||
---
|
||||
title: "配置 Pods 和容器"
|
||||
weight: 20
|
||||
---
|
||||
|
||||
<!--
|
||||
title: "Configure Pods and Containers"
|
||||
weight: 20
|
||||
---
|
||||
-->
|
||||
|
||||
---
|
||||
title: "配置 Pod 和 容器"
|
||||
weight: 20
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
<!--
|
||||
---
|
||||
title: Assign CPU Resources to Containers and Pods
|
||||
content_template: templates/task
|
||||
weight: 20
|
||||
---
|
||||
-->
|
||||
|
||||
---
|
||||
title: 为容器和 Pods 分配 CPU 资源
|
||||
content_template: templates/task
|
||||
weight: 20
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
This page shows how to assign a CPU *request* and a CPU *limit* to
|
||||
a container. Containers cannot use more CPU than the configured limit.
|
||||
Provided the system has CPU time free, a container is guaranteed to be
|
||||
allocated as much CPU as it requests.
|
||||
-->
|
||||
此页面显示如何将 CPU *request* 和 CPU *limit* 分配给一个容器。容器使用的 CPU 不能超过配额限制。
|
||||
如果系统有空闲的 CPU 时间,则可以保证根据请求给容器分配尽可能多的 CPU 资源。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
Each node in your cluster must have at least 1 CPU.
|
||||
|
||||
A few of the steps on this page require you to run the
|
||||
[metrics-server](https://github.com/kubernetes-incubator/metrics-server)
|
||||
service in your cluster. If you have the metrics-server
|
||||
running, you can skip those steps.
|
||||
|
||||
If you are running {{< glossary_tooltip term_id="minikube" >}}, run the
|
||||
following command to enable metrics-server:
|
||||
-->
|
||||
|
||||
集群中的每个节点必须至少具有 1 个 CPU。
|
||||
|
||||
此页面上的一些步骤要求您在集群中运行[metrics-server](https://github.com/kubernetes-incubator/metrics-server)
|
||||
服务。如果您的集群中已经有正在运行的 metrics-server 服务,那么您可以跳过这些步骤。
|
||||
|
||||
如果您正在运行{{< glossary_tooltip term_id="minikube" >}},请运行以下命令启用 metrics-server:
|
||||
|
||||
|
||||
```shell
|
||||
minikube addons enable metrics-server
|
||||
```
|
||||
<!--
|
||||
To see whether metrics-server (or another provider of the resource metrics
|
||||
API, `metrics.k8s.io`) is running, type the following command:
|
||||
-->
|
||||
|
||||
查看是 metrics-server(或者其他资源度量 API 服务提供者,`metrics.k8s.io` )是否正在运行,请键入以下命令:
|
||||
|
||||
```shell
|
||||
kubectl get API services
|
||||
```
|
||||
<!--
|
||||
If the resource metrics API is available, the output will include a
|
||||
reference to `metrics.k8s.io`.
|
||||
-->
|
||||
|
||||
如果资源指标 API 可用,则会输出将包含一个参考信息 `metrics.k8s.io`。
|
||||
|
||||
|
||||
```
|
||||
NAME
|
||||
v1beta1.metrics.k8s.io
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
|
||||
<!--
|
||||
## Create a namespace
|
||||
|
||||
Create a {{< glossary_tooltip term_id="namespace" >}} so that the resources you
|
||||
create in this exercise are isolated from the rest of your cluster.
|
||||
-->
|
||||
## 创建一个命名空间
|
||||
创建一个命名空间 {{< glossary_tooltip term_id="namespace" >}},以便在本练习中创建的资源与集群的其余部分资源隔离。
|
||||
|
||||
```shell
|
||||
kubectl create namespace CPU -example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Specify a CPU request and a CPU limit
|
||||
|
||||
To specify a CPU request for a container, include the `resources:requests` field
|
||||
in the Container resource manifest. To specify a CPU limit, include `resources:limits`.
|
||||
|
||||
In this exercise, you create a Pod that has one container. The container has a request
|
||||
of 0.5 CPU and a limit of 1 CPU. Here is the configuration file for the Pod:
|
||||
|
||||
{{< codenew file="pods/resource/cpu-request-limit.yaml" >}}
|
||||
|
||||
The `args` section of the configuration file provides arguments for the container when it starts.
|
||||
The `-cpus "2"` argument tells the Container to attempt to use 2 CPUs.
|
||||
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
## 指定一个 CPU 请求和 CPU 限制
|
||||
|
||||
要为容器指定 CPU 请求,请包含 `resources:requests` 字段
|
||||
在容器资源清单中。要指定 CPU 限制,请包含 `resources:limits`。
|
||||
|
||||
在本练习中,您将创建一个具有一个容器的 Pod。容器将会请求 0.5 个 CPU,而且最多限制使用 1 个 CPU。
|
||||
这是 Pod 的配置文件:
|
||||
|
||||
{{< codenew file="pods/resource/cpu-request-limit.yaml" >}}
|
||||
|
||||
配置文件的 `args` 部分提供了容器启动时的参数。
|
||||
-cpus "2"参数告诉容器尝试使用 2 个 CPU。
|
||||
|
||||
创建 Pod 命令如下:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/resource/cpu-request-limit.yaml --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
Verify that the Pod is running:
|
||||
-->
|
||||
验证上述创建的 Pod 处于 Running 状态
|
||||
|
||||
```shell
|
||||
kubectl get pod cpu-demo --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod:
|
||||
-->
|
||||
查看显示关于 Pod 的详细信息
|
||||
|
||||
```shell
|
||||
kubectl get pod cpu-demo --output=yaml --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that the one container in the Pod has a CPU request of 500 milliCPU
|
||||
and a CPU limit of 1 CPU.
|
||||
-->
|
||||
|
||||
输出显示 Pod 中的一个容器的 CPU 请求为 500 milli CPU,并且 CPU 限制为 1 个 CPU。
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
limits:
|
||||
CPU : "1"
|
||||
requests:
|
||||
CPU : 500m
|
||||
```
|
||||
|
||||
<!--
|
||||
Use `kubectl top` to fetch the metrics for the pod:
|
||||
-->
|
||||
使用 `kubectl top` 命令来获取该 Pod 的指标数据:
|
||||
|
||||
```shell
|
||||
kubectl top pod cpu-demo --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
This example output shows that the Pod is using 974 milliCPU, which is
|
||||
just a bit less than the limit of 1 CPU specified in the Pod configuration.
|
||||
-->
|
||||
此示例的输出,显示 Pod 使用的是974 milliCPU,即仅略低于 Pod 配置中指定的 1 个 CPU 的限制。
|
||||
```
|
||||
NAME CPU (cores) MEMORY(bytes)
|
||||
CPU -demo 974m <something>
|
||||
```
|
||||
<!--
|
||||
Recall that by setting `-cpu "2"`, you configured the Container to attempt to use 2 CPUs, but the Container is only being allowed to use about 1 CPU. The container's CPU use is being throttled, because the container is attempting to use more CPU resources than its limit.
|
||||
-->
|
||||
回想一下,通过设置 `- CPU "2"`,您将容器配置为尝试使用 2 个 CPU,但是只允许容器使用大约 1 个 CPU。容器的 CPU 使用量受到限制,因为该容器正尝试使用超出其限制的 CPU 资源。
|
||||
|
||||
|
||||
<!--
|
||||
{{< note >}}
|
||||
Another possible explanation for the CPU use being below 1.0 is that the Node might not have
|
||||
enough CPU resources available. Recall that the prerequisites for this exercise require each of
|
||||
your Nodes to have at least 1 CPU. If your Container runs on a Node that has only 1 CPU, the Container
|
||||
cannot use more than 1 CPU regardless of the CPU limit specified for the Container.
|
||||
{{< /note >}}
|
||||
-->
|
||||
|
||||
{{< note >}}
|
||||
CPU 使用率低于1.0的另一种可能的解释是,节点可能没有足够的 CPU 资源可用。回想一下,此练习的先决条件需要
|
||||
您的节点至少具有 1 个 CPU。如果您的容器在只有 1 个 CPU 的节点上运行,则容器无论为容器指定的 CPU 限制如何,都不能使用超过 1 个 CPU。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## CPU units
|
||||
|
||||
The CPU resource is measured in *CPU* units. One CPU, in Kubernetes, is equivalent to:
|
||||
|
||||
* 1 AWS vCPU
|
||||
* 1 GCP Core
|
||||
* 1 Azure vCore
|
||||
* 1 Hyperthread on a bare-metal Intel processor with Hyperthreading
|
||||
-->
|
||||
|
||||
## CPU 单元
|
||||
CPU 资源以 *CPU* 单位度量。Kubernetes中的一个 CPU 等同于:
|
||||
|
||||
* 1 个 AWS vCPU
|
||||
* 1 个 GCP核心
|
||||
* 1 个 Azure vCore
|
||||
* 1 个具有超线程功能的裸机英特尔处理器上的超线程
|
||||
|
||||
<!--
|
||||
Fractional values are allowed. A Container that requests 0.5 CPU is guaranteed half as much
|
||||
CPU as a Container that requests 1 CPU. You can use the suffix m to mean milli. For example
|
||||
100m CPU, 100 milliCPU, and 0.1 CPU are all the same. Precision finer than 1m is not allowed.
|
||||
|
||||
CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same
|
||||
amount of CPU on a single-core, dual-core, or 48-core machine.
|
||||
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
允许使用小数值。要求 0.5 CPU 的容器保证一半 CPU 作为请求 1 个 CPU 的容器。
|
||||
您可以使用后缀 m 表示毫。例如 100m CPU,100 milliCPU 和 0.1 CPU 都相同。
|
||||
精度不能超过 1m。
|
||||
|
||||
始终要求 CPU 是绝对数量,而不是相对数量。0.1 在单核,双核或 48 核计算机上的 CPU 数量值是一样的。
|
||||
|
||||
|
||||
```shell
|
||||
kubectl delete pod cpu-demo --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Specify a CPU request that is too big for your Nodes
|
||||
|
||||
CPU requests and limits are associated with Containers, but it is useful to think
|
||||
of a Pod as having a CPU request and limit. The CPU request for a Pod is the sum
|
||||
of the CPU requests for all the Containers in the Pod. Likewise, the CPU limit for
|
||||
a Pod is the sum of the CPU limits for all the Containers in the Pod.
|
||||
|
||||
Pod scheduling is based on requests. A Pod is scheduled to run on a Node only if
|
||||
the Node has enough CPU resources available to satisfy the Pod CPU request.
|
||||
|
||||
In this exercise, you create a Pod that has a CPU request so big that it exceeds
|
||||
the capacity of any Node in your cluster. Here is the configuration file for a Pod
|
||||
that has one Container. The Container requests 100 CPU, which is likely to exceed the
|
||||
capacity of any Node in your cluster.
|
||||
|
||||
{{< codenew file="pods/resource/cpu-request-limit-2.yaml" >}}
|
||||
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
|
||||
## 对您的节点而言,设置一个 CPU 过大的请求
|
||||
|
||||
CPU 请求和限制与容器相关联,但是我们可以考虑一下 CPU 对应 Pod 的请求和限制这样的场景:Pod 对 CPU 使用量的请求等于 Pod 中所有容器的请求数量。
|
||||
同样,CPU 对 Pod 请求资源的限制等于 Pod 中所有容器的请求的 CPU 资源限制数。
|
||||
|
||||
Pod 调度基于请求。仅在以下情况下,Pod 将会在节点上运行:节点具有足够的 CPU 资源可用于满足 Pod CPU 请求。
|
||||
|
||||
在本练习中,您将创建一个 Pod,该 Pod 的 CPU 请求对于集群中任何节点的容量而言都会过大。
|
||||
|
||||
这是 Pod 的配置文件,Pod 中有一个容器。容器请求 100 个 CPU,这可能会超出集群中任何节点的容量。
|
||||
|
||||
{{< codenew file="pods/resource/cpu-request-limit-2.yaml" >}}
|
||||
|
||||
使用如下命令创建该 Pod
|
||||
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/resource/cpu-request-limit-2.yaml --namespace=cpu-example
|
||||
```
|
||||
<!--
|
||||
View the Pod status:
|
||||
-->
|
||||
查看该 Pod 的状态
|
||||
|
||||
```shell
|
||||
kubectl get pod cpu-demo-2 --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that the Pod status is Pending. That is, the Pod has not been
|
||||
scheduled to run on any Node, and it will remain in the Pending state indefinitely:
|
||||
-->
|
||||
|
||||
输出显示 Pod 状态为Pending。也就是说,尚未将 Pod 调度到任何节点上运行,
|
||||
并且 Pod 将无限期地处于Pending状态:
|
||||
|
||||
```shell
|
||||
kubectl get pod cpu-demo-2 --namespace=cpu-example
|
||||
```
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
cpu-demo-2 0/1 Pending 0 7m
|
||||
```
|
||||
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod, including events:
|
||||
-->
|
||||
|
||||
查看有关 Pod 的详细信息,包括事件如下:
|
||||
```shell
|
||||
kubectl describe pod cpu-demo-2 --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that the Container cannot be scheduled because of insufficient
|
||||
CPU resources on the Nodes:
|
||||
-->
|
||||
|
||||
输出显示由于节点上的 CPU 资源不足,无法调度容器
|
||||
|
||||
```
|
||||
Events:
|
||||
Reason Message
|
||||
------ -------
|
||||
FailedScheduling No nodes are available that match all of the following predicates:: Insufficient cpu (3).
|
||||
```
|
||||
|
||||
<!--
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
删除您的 Pod
|
||||
|
||||
```shell
|
||||
kubectl delete pod cpu-demo-2 --namespace=cpu-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## If you do not specify a CPU limit
|
||||
|
||||
If you do not specify a CPU limit for a Container, then one of these situations applies:
|
||||
|
||||
* The Container has no upper bound on the CPU resources it can use. The Container
|
||||
could use all of the CPU resources available on the Node where it is running.
|
||||
|
||||
* The Container is running in a namespace that has a default CPU limit, and the
|
||||
Container is automatically assigned the default limit. Cluster administrators can use a
|
||||
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core/)
|
||||
to specify a default value for the CPU limit.
|
||||
-->
|
||||
## 如果没有指定 CPU 限制
|
||||
|
||||
如果您没有为容器指定 CPU 限制,则适用以下情况之一:
|
||||
|
||||
* 容器在可以使用的 CPU 资源上没有上限。容器可以使用运行该节点的所有可用 CPU 资源。
|
||||
|
||||
* 容器在具有默认 CPU 限制的命名空间中运行,并且系统会自动为容器分配默认限制。集群管理员可以使用
|
||||
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core/)
|
||||
指定 CPU 限制的默认值。
|
||||
|
||||
|
||||
<!--
|
||||
## Motivation for CPU requests and limits
|
||||
|
||||
By configuring the CPU requests and limits of the Containers that run in your
|
||||
cluster, you can make efficient use of the CPU resources available on your cluster
|
||||
Nodes. By keeping a Pod CPU request low, you give the Pod a good chance of being
|
||||
scheduled. By having a CPU limit that is greater than the CPU request, you accomplish two things:
|
||||
|
||||
* The Pod can have bursts of activity where it makes use of CPU resources that happen to be available.
|
||||
* The amount of CPU resources a Pod can use during a burst is limited to some reasonable amount.
|
||||
-->
|
||||
|
||||
## CPU 请求和限制的初衷
|
||||
|
||||
通过配置 CPU 请求和在您的容器中运行的容器的限制
|
||||
集群,您可以有效利用集群上可用的 CPU 资源
|
||||
节点。通过将 Pod CPU 请求保持在较低水平,可以使 Pod 成为
|
||||
预定的。通过使 CPU 限制大于 CPU 请求,您可以完成两件事:
|
||||
|
||||
* Pod 可能会有大量活动,它利用恰好可用的 CPU 资源。
|
||||
* Pod 在突发期间可以使用的 CPU 资源数量被限制为合理的数量。
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
-->
|
||||
|
||||
## 清理
|
||||
|
||||
删除名称空间:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace cpu-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
-->
|
||||
### 针对应用开发者
|
||||
* [将内存资源分配给容器和 Pod](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [配置 Pod 服务质量](/docs/tasks/configure-pod-container/quality-service-pod/)
|
||||
|
||||
<!--
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
-->
|
||||
### 针对集群管理员
|
||||
|
||||
* [配置名称空间的默认内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [为命名空间配置默认的 CPU 请求和限制](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [为命名空间配置最小和最大内存限制](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [为命名空间配置最小和最大 CPU 约束](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [配置 API 对象的配额](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
@@ -66,7 +66,7 @@ Kubernetes cluster.
|
||||
-->
|
||||
1. 验证你选择的节点是否有 `disktype=ssd` 标签:
|
||||
|
||||
kubectl get nodes --show-labels
|
||||
kubectl get nodes --show-labels
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
@@ -32,7 +32,6 @@ Kubernetes 将发送一个 preStop 事件。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
---
|
||||
title: 配置 Pod 以使用 PersistentVolume 作为存储
|
||||
content_template: templates/task
|
||||
weight: 60
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: Configure a Pod to Use a PersistentVolume for Storage
|
||||
content_template: templates/task
|
||||
weight: 60
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
This page shows how to configure a Pod to use a PersistentVolumeClaim for storage.
|
||||
Here is a summary of the process:
|
||||
|
||||
1. A cluster administrator creates a PersistentVolume that is backed by physical
|
||||
storage. The administrator does not associate the volume with any Pod.
|
||||
|
||||
1. A cluster user creates a PersistentVolumeClaim, which gets automatically
|
||||
bound to a suitable PersistentVolume.
|
||||
|
||||
1. The user creates a Pod that uses the PersistentVolumeClaim as storage.
|
||||
-->
|
||||
|
||||
本文介绍如何配置 Pod 使用 PersistentVolumeClaim 作为存储。
|
||||
以下是该过程的总结:
|
||||
|
||||
1. 集群管理员创建由物理存储支持的 PersistentVolume。管理员不将卷与任何 Pod 关联。
|
||||
|
||||
1. 群集用户创建一个 PersistentVolumeClaim,它将自动绑定到合适的 PersistentVolume。
|
||||
|
||||
1. 用户创建一个使用 PersistentVolumeClaim 作为存储的 Pod。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
<!--
|
||||
* You need to have a Kubernetes cluster that has only one Node, and the kubectl
|
||||
command-line tool must be configured to communicate with your cluster. If you
|
||||
do not already have a single-node cluster, you can create one by using
|
||||
[Minikube](/docs/getting-started-guides/minikube).
|
||||
|
||||
* Familiarize yourself with the material in
|
||||
[Persistent Volumes](/docs/concepts/storage/persistent-volumes/).
|
||||
-->
|
||||
|
||||
* 您需要一个包含单个节点的 Kubernetes 集群,并且必须配置 kubectl 命令行工具以便与集群交互。
|
||||
如果还没有单节点集群,可以使用 [Minikube](/docs/getting-started-guides/minikube) 创建一个。
|
||||
|
||||
* 熟悉[持久卷](/docs/concepts/storage/persistent-volumes/)中的材料。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Create an index.html file on your Node
|
||||
|
||||
Open a shell to the Node in your cluster. How you open a shell depends on how
|
||||
you set up your cluster. For example, if you are using Minikube, you can open a
|
||||
shell to your Node by entering `minikube ssh`.
|
||||
|
||||
In your shell, create a `/mnt/data` directory:
|
||||
-->
|
||||
|
||||
## 在你的节点上创建一个 index.html 文件
|
||||
|
||||
打开集群中节点的一个 shell。
|
||||
如何打开 shell 取决于集群的设置。
|
||||
例如,如果您正在使用 Minikube,那么可以通过输入 `minikube ssh` 来打开节点的 shell。
|
||||
|
||||
在 shell 中,创建一个 `/mnt/data` 目录:
|
||||
|
||||
mkdir /mnt/data
|
||||
|
||||
<!--
|
||||
In the `/mnt/data` directory, create an `index.html` file:
|
||||
-->
|
||||
|
||||
在 `/mnt/data` 目录中创建一个 index.html 文件:
|
||||
|
||||
echo 'Hello from Kubernetes storage' > /mnt/data/index.html
|
||||
|
||||
<!--
|
||||
## Create a PersistentVolume
|
||||
|
||||
In this exercise, you create a *hostPath* PersistentVolume. Kubernetes supports
|
||||
hostPath for development and testing on a single-node cluster. A hostPath
|
||||
PersistentVolume uses a file or directory on the Node to emulate network-attached storage.
|
||||
-->
|
||||
|
||||
## 创建 PersistentVolume
|
||||
|
||||
在本练习中,您将创建一个 *hostPath* 类型的 PersistentVolume。
|
||||
Kubernetes 支持用于在单节点集群上开发和测试的 hostPath 类型的 PersistentVolume。
|
||||
hostPath 类型的 PersistentVolume 使用节点上的文件或目录来模拟附带网络的存储。
|
||||
|
||||
<!--
|
||||
In a production cluster, you would not use hostPath. Instead a cluster administrator
|
||||
would provision a network resource like a Google Compute Engine persistent disk,
|
||||
an NFS share, or an Amazon Elastic Block Store volume. Cluster administrators can also
|
||||
use [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage)
|
||||
to set up
|
||||
[dynamic provisioning](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes).
|
||||
|
||||
Here is the configuration file for the hostPath PersistentVolume:
|
||||
-->
|
||||
|
||||
在生产集群中,您不会使用 hostPath。集群管理员会提供网络存储资源,比如 Google Compute Engine 持久盘卷、NFS 共享卷或 Amazon Elastic Block Store 卷。
|
||||
集群管理员还可以使用 [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage) 来设置[动态提供存储](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes)。
|
||||
|
||||
下面是 hostPath PersistentVolume 的配置文件:
|
||||
|
||||
{{< codenew file="pods/storage/pv-volume.yaml" >}}
|
||||
|
||||
<!--
|
||||
The configuration file specifies that the volume is at `/mnt/data` on the
|
||||
cluster's Node. The configuration also specifies a size of 10 gibibytes and
|
||||
an access mode of `ReadWriteOnce`, which means the volume can be mounted as
|
||||
read-write by a single Node. It defines the [StorageClass name](/docs/concepts/storage/persistent-volumes/#class)
|
||||
`manual` for the PersistentVolume, which will be used to bind
|
||||
PersistentVolumeClaim requests to this PersistentVolume.
|
||||
|
||||
Create the PersistentVolume:
|
||||
-->
|
||||
|
||||
配置文件指定了该卷位于集群节点上的 `/mnt/data` 目录。
|
||||
该配置还指定了 10 吉比特的卷大小和 `ReadWriteOnce` 的访问模式,这意味着该卷可以在单个节点上以读写方式挂载。
|
||||
它为 PersistentVolume 定义了 [StorageClass 名称](/docs/concepts/storage/persistent-volumes/#class) 为 `manual`,StorageClass 名称用来将 PersistentVolumeClaim 请求绑定到该 PersistentVolum。
|
||||
|
||||
创建 PersistentVolume:
|
||||
|
||||
kubectl create -f https://k8s.io/examples/pods/storage/pv-volume.yaml
|
||||
|
||||
<!--
|
||||
View information about the PersistentVolume:
|
||||
-->
|
||||
|
||||
查看 PersistentVolume 的信息:
|
||||
|
||||
kubectl get pv task-pv-volume
|
||||
|
||||
<!--
|
||||
The output shows that the PersistentVolume has a `STATUS` of `Available`. This
|
||||
means it has not yet been bound to a PersistentVolumeClaim.
|
||||
-->
|
||||
|
||||
输出结果显示该 PersistentVolume 的`状态(STATUS)` 为 `Available`。
|
||||
这意味着它还没有被绑定给 PersistentVolumeClaim。
|
||||
|
||||
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
|
||||
task-pv-volume 10Gi RWO Retain Available manual 4s
|
||||
|
||||
<!--
|
||||
## Create a PersistentVolumeClaim
|
||||
|
||||
The next step is to create a PersistentVolumeClaim. Pods use PersistentVolumeClaims
|
||||
to request physical storage. In this exercise, you create a PersistentVolumeClaim
|
||||
that requests a volume of at least three gibibytes that can provide read-write
|
||||
access for at least one Node.
|
||||
|
||||
Here is the configuration file for the PersistentVolumeClaim:
|
||||
-->
|
||||
|
||||
## 创建 PersistentVolumeClaim
|
||||
|
||||
下一步是创建一个 PersistentVolumeClaim。
|
||||
Pod 使用 PersistentVolumeClaim 来请求物理存储。
|
||||
在本练习中,您将创建一个 PersistentVolumeClaim,它请求至少 3 吉比特容量的卷,该卷至少可以为一个节点提供读写访问。
|
||||
|
||||
下面是 PersistentVolumeClaim 的配置文件:
|
||||
|
||||
{{< codenew file="pods/storage/pv-claim.yaml" >}}
|
||||
|
||||
<!--
|
||||
Create the PersistentVolumeClaim:
|
||||
-->
|
||||
|
||||
创建 PersistentVolumeClaim:
|
||||
|
||||
kubectl create -f https://k8s.io/examples/pods/storage/pv-claim.yaml
|
||||
|
||||
<!--
|
||||
After you create the PersistentVolumeClaim, the Kubernetes control plane looks
|
||||
for a PersistentVolume that satisfies the claim's requirements. If the control
|
||||
plane finds a suitable PersistentVolume with the same StorageClass, it binds the
|
||||
claim to the volume.
|
||||
|
||||
Look again at the PersistentVolume:
|
||||
-->
|
||||
|
||||
创建 PersistentVolumeClaim 之后,Kubernetes 控制平面将查找满足申领要求的 PersistentVolume。
|
||||
如果控制平面找到具有相同 StorageClass 的适当的 PersistentVolume,则将 PersistentVolumeClaim 绑定到该 PersistentVolume 上。
|
||||
|
||||
再次查看 PersistentVolume 信息:
|
||||
|
||||
kubectl get pv task-pv-volume
|
||||
|
||||
<!--
|
||||
Now the output shows a `STATUS` of `Bound`.
|
||||
-->
|
||||
现在输出的 `STATUS` 为 `Bound`。
|
||||
|
||||
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
|
||||
task-pv-volume 10Gi RWO Retain Bound default/task-pv-claim manual 2m
|
||||
|
||||
<!--
|
||||
Look at the PersistentVolumeClaim:
|
||||
-->
|
||||
查看 PersistentVolumeClaim:
|
||||
|
||||
kubectl get pvc task-pv-claim
|
||||
|
||||
<!--
|
||||
The output shows that the PersistentVolumeClaim is bound to your PersistentVolume,
|
||||
`task-pv-volume`.
|
||||
-->
|
||||
|
||||
输出结果表明该 PersistentVolumeClaim 绑定了你的 PersistentVolume `task-pv-volume`。
|
||||
|
||||
NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
|
||||
task-pv-claim Bound task-pv-volume 10Gi RWO manual 30s
|
||||
|
||||
<!--
|
||||
## Create a Pod
|
||||
|
||||
The next step is to create a Pod that uses your PersistentVolumeClaim as a volume.
|
||||
|
||||
Here is the configuration file for the Pod:
|
||||
-->
|
||||
|
||||
## 创建 Pod
|
||||
|
||||
下一步是创建一个 Pod, 该 Pod 使用你的 PersistentVolumeClaim 作为存储卷。
|
||||
|
||||
下面是 Pod 的 配置文件:
|
||||
|
||||
{{< codenew file="pods/storage/pv-pod.yaml" >}}
|
||||
|
||||
<!--
|
||||
Notice that the Pod's configuration file specifies a PersistentVolumeClaim, but
|
||||
it does not specify a PersistentVolume. From the Pod's point of view, the claim
|
||||
is a volume.
|
||||
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
注意 Pod 的配置文件指定了 PersistentVolumeClaim,但没有指定 PersistentVolume。对 Pod 而言,PersistentVolumeClaim 就是一个存储卷。
|
||||
|
||||
创建 Pod:
|
||||
|
||||
kubectl create -f https://k8s.io/examples/pods/storage/pv-pod.yaml
|
||||
|
||||
<!--
|
||||
Verify that the Container in the Pod is running;
|
||||
-->
|
||||
|
||||
检查 Pod 中的容器是否运行正常:
|
||||
|
||||
kubectl get pod task-pv-pod
|
||||
|
||||
<!--
|
||||
Get a shell to the Container running in your Pod:
|
||||
-->
|
||||
|
||||
打开一个 shell 访问 Pod 中的容器:
|
||||
|
||||
kubectl exec -it task-pv-pod -- /bin/bash
|
||||
|
||||
<!--
|
||||
In your shell, verify that nginx is serving the `index.html` file from the
|
||||
hostPath volume:
|
||||
-->
|
||||
|
||||
在 shell 中,验证 nginx 是否正在从 hostPath 卷提供 `index.html` 文件:
|
||||
|
||||
root@task-pv-pod:/# apt-get update
|
||||
root@task-pv-pod:/# apt-get install curl
|
||||
root@task-pv-pod:/# curl localhost
|
||||
|
||||
<!--
|
||||
The output shows the text that you wrote to the `index.html` file on the
|
||||
hostPath volume:
|
||||
-->
|
||||
|
||||
输出结果是你之前写到 hostPath 卷中的 `index.html` 文件中的内容:
|
||||
|
||||
Hello from Kubernetes storage
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture discussion %}}
|
||||
|
||||
<!--
|
||||
## Access control
|
||||
|
||||
Storage configured with a group ID (GID) allows writing only by Pods using the same
|
||||
GID. Mismatched or missing GIDs cause permission denied errors. To reduce the
|
||||
need for coordination with users, an administrator can annotate a PersistentVolume
|
||||
with a GID. Then the GID is automatically added to any Pod that uses the
|
||||
PersistentVolume.
|
||||
|
||||
Use the `pv.beta.kubernetes.io/gid` annotation as follows:
|
||||
-->
|
||||
|
||||
## 访问控制
|
||||
|
||||
使用 group ID(GID)配置的存储仅允许 Pod 使用相同的 GID 进行写入。
|
||||
GID 不匹配或缺少将会导致许可被拒绝的错误。
|
||||
为了减少与用户的协调,管理员可以使用 GID 对 PersistentVolume 进行注解。
|
||||
这样 GID 就能自动的添加到使用 PersistentVolume 的任何 Pod 中。
|
||||
|
||||
使用 `pv.beta.kubernetes.io/gid` 注解的方法如下所示:
|
||||
|
||||
```yaml
|
||||
kind: PersistentVolume
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: pv1
|
||||
annotations:
|
||||
pv.beta.kubernetes.io/gid: "1234"
|
||||
```
|
||||
|
||||
<!--
|
||||
When a Pod consumes a PersistentVolume that has a GID annotation, the annotated GID
|
||||
is applied to all Containers in the Pod in the same way that GIDs specified in the
|
||||
Pod’s security context are. Every GID, whether it originates from a PersistentVolume
|
||||
annotation or the Pod’s specification, is applied to the first process run in
|
||||
each Container.
|
||||
-->
|
||||
|
||||
当 Pod 使用带有 GID 注解的 PersistentVolume 时,注解的 GID 会被应用于 Pod 中的所有容器,应用的方法与 Pod 的安全上下文中指定的 GID 相同。
|
||||
每个 GID,无论是来自 PersistentVolume 注解还是来自 Pod 的规范,都应用于每个容器中运行的第一个进程。
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
When a Pod consumes a PersistentVolume, the GIDs associated with the
|
||||
PersistentVolume are not present on the Pod resource itself.
|
||||
-->
|
||||
当 Pod 使用 PersistentVolume 时,与 PersistentVolume 关联的 GID 不会在 Pod 本身的资源对象上出现。
|
||||
{{< /note >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
* Learn more about [PersistentVolumes](/docs/concepts/storage/persistent-volumes/).
|
||||
* Read the [Persistent Storage design document](https://git.k8s.io/community/contributors/design-proposals/storage/persistent-storage.md).
|
||||
-->
|
||||
|
||||
* 进一步了解 [PersistentVolumes](/docs/concepts/storage/persistent-volumes/)。
|
||||
* 阅读[持久存储设计文档](https://git.k8s.io/community/contributors/design-proposals/storage/persistent-storage.md)。
|
||||
|
||||
<!--
|
||||
### Reference
|
||||
-->
|
||||
|
||||
### 参考
|
||||
|
||||
* [PersistentVolume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolume-v1-core)
|
||||
* [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core)
|
||||
* [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core)
|
||||
* [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core)
|
||||
|
||||
|
||||
{{% /capture %}}
|
||||
@@ -0,0 +1,848 @@
|
||||
---
|
||||
title: 使用 ConfigMap 配置 Pod
|
||||
content_template: templates/task
|
||||
weight: 150
|
||||
card:
|
||||
name: tasks
|
||||
weight: 50
|
||||
---
|
||||
<!-- ---
|
||||
title: Configure a Pod to Use a ConfigMap
|
||||
content_template: templates/task
|
||||
weight: 150
|
||||
card:
|
||||
name: tasks
|
||||
weight: 50
|
||||
--- -->
|
||||
|
||||
{{% capture overview %}}
|
||||
<!-- ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in ConfigMaps. -->
|
||||
ConfigMap 允许您将配置文件与镜像文件分离,以使容器化的应用程序具有可移植性。该页面提供了一系列使用示例,这些示例演示了如何使用存储在 ConfigMap 中的数据创建 ConfigMap 和配置 Pod。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
|
||||
<!-- ## Create a ConfigMap
|
||||
You can use either `kubectl create configmap` or a ConfigMap generator in `kustomization.yaml` to create a ConfigMap. Note that `kubectl` starts to support `kustomization.yaml` since 1.14. -->
|
||||
## 创建 ConfigMap
|
||||
您可以在 `kustomization.yaml` 中使用 `kubectl create configmap` 或 ConfigMap 生成器来创建ConfigMap。注意,从 1.14 版本开始, `kubectl` 开始支持 `kustomization.yaml`。
|
||||
|
||||
<!-- ### Create a ConfigMap Using kubectl create configmap -->
|
||||
### 使用 kubectl 创建 ConfigMap
|
||||
|
||||
<!-- Use the `kubectl create configmap` command to create configmaps from [directories](#create-configmaps-from-directories), [files](#create-configmaps-from-files), or [literal values](#create-configmaps-from-literal-values): -->
|
||||
在[目录](#create-configmaps-from-directories), [文件](#create-configmaps-from-files), 或者[文字值](#create-configmaps-from-literal-values)中使用 `kubectl create configmap` 命令创建configmap:
|
||||
|
||||
```shell
|
||||
kubectl create configmap <map-name> <data-source>
|
||||
```
|
||||
|
||||
<!-- where \<map-name> is the name you want to assign to the ConfigMap and \<data-source> is the directory, file, or literal value to draw the data from. -->
|
||||
其中, \<map-name> 是要分配给 ConfigMap 的名称,\<data-source> 是要从中提取数据的目录,文件或者文字值。
|
||||
|
||||
<!-- The data source corresponds to a key-value pair in the ConfigMap, where -->
|
||||
数据源对应于 ConfigMap 中的 key-value (键值对)
|
||||
|
||||
<!-- * key = the file name or the key you provided on the command line, and
|
||||
* value = the file contents or the literal value you provided on the command line. -->
|
||||
* key = 您在命令行上提供的文件名或者密钥
|
||||
* value = 您在命令行上提供的文件内容或者文字值
|
||||
|
||||
<!-- You can use [`kubectl describe`](/docs/reference/generated/kubectl/kubectl-commands/#describe) or
|
||||
[`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get) to retrieve information
|
||||
about a ConfigMap. -->
|
||||
您可以使用[`kubectl describe`](/docs/reference/generated/kubectl/kubectl-commands/#describe)或者
|
||||
[`kubectl get`](/docs/reference/generated/kubectl/kubectl-commands/#get)检索有关 ConfigMap 的信息。
|
||||
|
||||
<!-- #### Create ConfigMaps from directories
|
||||
|
||||
You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory. -->
|
||||
#### 根据目录创建 ConfigMap
|
||||
|
||||
<!-- You can use `kubectl create configmap` to create a ConfigMap from multiple files in the same directory.
|
||||
|
||||
For example: -->
|
||||
你可以使用 `kubectl create configmap` 从同一目录中的多个文件创建 ConfigMap。
|
||||
|
||||
例如:
|
||||
|
||||
# Create the local directory
|
||||
# Download the sample files into `configure-pod-container/configmap/` directory
|
||||
# Create the configmap
|
||||
```shell
|
||||
# 创建本地目录
|
||||
mkdir -p configure-pod-container/configmap/
|
||||
|
||||
# 将样本文件下载到 `configure-pod-container/configmap/` 目录
|
||||
wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
|
||||
wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties
|
||||
|
||||
# 创建 configmap
|
||||
kubectl create c game-config --from-file=configure-pod-container/configmap/
|
||||
```
|
||||
|
||||
<!-- combines the contents of the `configure-pod-container/configmap/` directory -->
|
||||
合并 `configure-pod-container/configmap/` 目录的内容
|
||||
|
||||
```shell
|
||||
game.properties
|
||||
ui.properties
|
||||
```
|
||||
|
||||
<!-- into the following ConfigMap: -->
|
||||
进入以下 ConfigMap 中:
|
||||
|
||||
```shell
|
||||
kubectl describe configmaps game-config
|
||||
```
|
||||
|
||||
<!-- where the output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
```
|
||||
Name: game-config
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Data
|
||||
====
|
||||
game.properties: 158 bytes
|
||||
ui.properties: 83 bytes
|
||||
```
|
||||
|
||||
<!-- The `game.properties` and `ui.properties` files in the `configure-pod-container/configmap/` directory are represented in the `data` section of the ConfigMap. -->
|
||||
`configure-pod-container/configmap/` 目录中的 `game.properties` 和 `ui.properties` 文件在 ConfigMap 的 `data` 部分中表示。
|
||||
|
||||
```shell
|
||||
kubectl get configmaps game-config -o yaml
|
||||
```
|
||||
<!-- The output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2016-02-18T18:52:05Z
|
||||
name: game-config
|
||||
namespace: default
|
||||
resourceVersion: "516"
|
||||
selfLink: /api/v1/namespaces/default/configmaps/game-config
|
||||
uid: b4952dc3-d670-11e5-8cd0-68f728db1985
|
||||
data:
|
||||
game.properties: |
|
||||
enemies=aliens
|
||||
lives=3
|
||||
enemies.cheat=true
|
||||
enemies.cheat.level=noGoodRotten
|
||||
secret.code.passphrase=UUDDLRLRBABAS
|
||||
secret.code.allowed=true
|
||||
secret.code.lives=30
|
||||
ui.properties: |
|
||||
color.good=purple
|
||||
color.bad=yellow
|
||||
allow.textmode=true
|
||||
how.nice.to.look=fairlyNice
|
||||
```
|
||||
|
||||
<!-- #### Create ConfigMaps from files -->
|
||||
#### 根据文件创建 ConfigMap
|
||||
|
||||
<!-- You can use `kubectl create configmap` to create a ConfigMap from an individual file, or from multiple files.
|
||||
|
||||
For example, -->
|
||||
您可以使用 `kubectl create configmap` 从单个文件或多个文件创建 ConfigMap。
|
||||
|
||||
例如
|
||||
|
||||
```shell
|
||||
kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties
|
||||
```
|
||||
|
||||
<!-- would produce the following ConfigMap: -->
|
||||
将产生以下 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl describe configmaps game-config-2
|
||||
```
|
||||
|
||||
<!-- where the output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
|
||||
```
|
||||
Name: game-config-2
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Data
|
||||
====
|
||||
game.properties: 158 bytes
|
||||
```
|
||||
|
||||
<!-- You can pass in the `--from-file` argument multiple times to create a ConfigMap from multiple data sources. -->
|
||||
您可以传入多个 `--from-file` 参数,从多个数据源创建 ConfigMap。
|
||||
|
||||
```shell
|
||||
kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties --from-file=configure-pod-container/configmap/ui.properties
|
||||
```
|
||||
|
||||
<!-- Describe the above `game-config-2` configmap created -->
|
||||
描述上面创建的 `game-config-2` configmap
|
||||
|
||||
```shell
|
||||
kubectl describe configmaps game-config-2
|
||||
```
|
||||
|
||||
<!-- The output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
|
||||
```
|
||||
Name: game-config-2
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Data
|
||||
====
|
||||
game.properties: 158 bytes
|
||||
ui.properties: 83 bytes
|
||||
```
|
||||
|
||||
<!-- Use the option `--from-env-file` to create a ConfigMap from an env-file, for example: -->
|
||||
使用 `--from-env-file` 选项从环境文件创建 ConfigMap,例如:
|
||||
|
||||
<!-- ```shell
|
||||
# Env-files contain a list of environment variables.
|
||||
# These syntax rules apply:
|
||||
# Each line in an env file has to be in VAR=VAL format.
|
||||
# Lines beginning with # (i.e. comments) are ignored.
|
||||
# Blank lines are ignored.
|
||||
# There is no special handling of quotation marks (i.e. they will be part of the ConfigMap value)).
|
||||
|
||||
# Download the sample files into `configure-pod-container/configmap/` directory
|
||||
wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
|
||||
|
||||
# The env-file `game-env-file.properties` looks like below
|
||||
cat configure-pod-container/configmap/game-env-file.properties
|
||||
enemies=aliens
|
||||
lives=3
|
||||
allowed="true" -->
|
||||
```shell
|
||||
# 环境文件包含环境变量列表。
|
||||
# 语法规则:
|
||||
# env 文件中的每一行必须为 VAR = VAL 格式。
|
||||
# 以#开头的行(即注释)将被忽略。
|
||||
# 空行将被忽略。
|
||||
# 引号没有特殊处理(即它们将成为 ConfigMap 值的一部分)。
|
||||
|
||||
# 将样本文件下载到 `configure-pod-container/configmap/` 目录
|
||||
wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
|
||||
|
||||
# env文件 `game-env-file.properties` 如下所示
|
||||
cat configure-pod-container/configmap/game-env-file.properties
|
||||
enemies=aliens
|
||||
lives=3
|
||||
allowed="true"
|
||||
|
||||
# 注释及其上方的空行将被忽略
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl create configmap game-config-env-file \
|
||||
--from-env-file=configure-pod-container/configmap/game-env-file.properties
|
||||
```
|
||||
|
||||
<!-- would produce the following ConfigMap: -->
|
||||
将产生以下 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl get configmap game-config-env-file -o yaml
|
||||
```
|
||||
|
||||
<!-- where the output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2017-12-27T18:36:28Z
|
||||
name: game-config-env-file
|
||||
namespace: default
|
||||
resourceVersion: "809965"
|
||||
selfLink: /api/v1/namespaces/default/configmaps/game-config-env-file
|
||||
uid: d9d1ca5b-eb34-11e7-887b-42010a8002b8
|
||||
data:
|
||||
allowed: '"true"'
|
||||
enemies: aliens
|
||||
lives: "3"
|
||||
```
|
||||
|
||||
<!-- When passing `--from-env-file` multiple times to create a ConfigMap from multiple data sources, only the last env-file is used: -->
|
||||
当使用多个 `--from-env-file` 来从多个数据源创建 ConfigMap 时,仅仅最后一个 env 文件有效:
|
||||
|
||||
<!-- ```shell
|
||||
# Download the sample files into `configure-pod-container/configmap/` directory
|
||||
wget https://k8s.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
|
||||
|
||||
# Create the configmap
|
||||
kubectl create configmap config-multi-env-files \
|
||||
--from-env-file=configure-pod-container/configmap/game-env-file.properties \
|
||||
--from-env-file=configure-pod-container/configmap/ui-env-file.properties
|
||||
``` -->
|
||||
```shell
|
||||
# 将样本文件下载到 `configure-pod-container/configmap/` 目录
|
||||
wget https://k8s.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
|
||||
|
||||
# 创建 configmap
|
||||
kubectl create configmap config-multi-env-files \
|
||||
--from-env-file=configure-pod-container/configmap/game-env-file.properties \
|
||||
--from-env-file=configure-pod-container/configmap/ui-env-file.properties
|
||||
```
|
||||
|
||||
<!-- would produce the following ConfigMap: -->
|
||||
将产生以下 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl get configmap config-multi-env-files -o yaml
|
||||
```
|
||||
|
||||
<!-- where the output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2017-12-27T18:38:34Z
|
||||
name: config-multi-env-files
|
||||
namespace: default
|
||||
resourceVersion: "810136"
|
||||
selfLink: /api/v1/namespaces/default/configmaps/config-multi-env-files
|
||||
uid: 252c4572-eb35-11e7-887b-42010a8002b8
|
||||
data:
|
||||
color: purple
|
||||
how: fairlyNice
|
||||
textmode: "true"
|
||||
```
|
||||
|
||||
<!-- #### Define the key to use when creating a ConfigMap from a file -->
|
||||
#### 定义从文件创建 ConfigMa p时要使用的密钥
|
||||
|
||||
<!-- You can define a key other than the file name to use in the `data` section of your ConfigMap when using the `--from-file` argument: -->
|
||||
您可以在使用 `--from-file` 参数时,在 ConfigMap 的 `data` 部分中定义除文件名以外的其他键:
|
||||
|
||||
```shell
|
||||
kubectl create configmap game-config-3 --from-file=<my-key-name>=<path-to-file>
|
||||
```
|
||||
|
||||
<!-- where `<my-key-name>` is the key you want to use in the ConfigMap and `<path-to-file>` is the location of the data source file you want the key to represent. -->
|
||||
`<my-key-name>` 是您要在 ConfigMap 中使用的密钥, `<path-to-file>` 是您想要键表示数据源文件的位置。
|
||||
|
||||
<!-- For example: -->
|
||||
例如:
|
||||
|
||||
```shell
|
||||
kubectl create configmap game-config-3 --from-file=game-special-key=configure-pod-container/configmap/game.properties
|
||||
```
|
||||
|
||||
<!-- would produce the following ConfigMap: -->
|
||||
将产生以下 ConfigMap:
|
||||
```
|
||||
kubectl get configmaps game-config-3 -o yaml
|
||||
```
|
||||
|
||||
<!-- where the output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2016-02-18T18:54:22Z
|
||||
name: game-config-3
|
||||
namespace: default
|
||||
resourceVersion: "530"
|
||||
selfLink: /api/v1/namespaces/default/configmaps/game-config-3
|
||||
uid: 05f8da22-d671-11e5-8cd0-68f728db1985
|
||||
data:
|
||||
game-special-key: |
|
||||
enemies=aliens
|
||||
lives=3
|
||||
enemies.cheat=true
|
||||
enemies.cheat.level=noGoodRotten
|
||||
secret.code.passphrase=UUDDLRLRBABAS
|
||||
secret.code.allowed=true
|
||||
secret.code.lives=30
|
||||
```
|
||||
|
||||
<!-- #### Create ConfigMaps from literal values -->
|
||||
#### 根据文字值创建 ConfigMap
|
||||
|
||||
<!-- You can use `kubectl create configmap` with the `--from-literal` argument to define a literal value from the command line: -->
|
||||
您可以将 `kubectl create configmap` 与 `--from-literal` 参数一起使用,从命令行定义文字值:
|
||||
|
||||
```shell
|
||||
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
|
||||
```
|
||||
|
||||
<!-- You can pass in multiple key-value pairs. Each pair provided on the command line is represented as a separate entry in the `data` section of the ConfigMap. -->
|
||||
您可以传入多个键值对。命令行中提供的每对在 ConfigMap 的 `data` 部分中均表示为单独的条目。
|
||||
|
||||
```shell
|
||||
kubectl get configmaps special-config -o yaml
|
||||
```
|
||||
|
||||
<!-- The output is similar to this: -->
|
||||
输出类似以下内容:
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2016-02-18T19:14:38Z
|
||||
name: special-config
|
||||
namespace: default
|
||||
resourceVersion: "651"
|
||||
selfLink: /api/v1/namespaces/default/configmaps/special-config
|
||||
uid: dadce046-d673-11e5-8cd0-68f728db1985
|
||||
data:
|
||||
special.how: very
|
||||
special.type: charm
|
||||
```
|
||||
|
||||
<!-- ### Create a ConfigMap from generator -->
|
||||
#### 根据生成器创建 ConfigMap
|
||||
<!-- `kubectl` supports `kustomization.yaml` since 1.14.
|
||||
You can also create a ConfigMap from generators and then apply it to create the object on
|
||||
the Apiserver. The generators
|
||||
should be specified in a `kustomization.yaml` inside a directory. -->
|
||||
自 1.14 开始, `kubectl` 开始支持 `kustomization.yaml`。
|
||||
您还可以从生成器创建 ConfigMap,然后将其应用于 Apiserver 创建对象。生成器应在目录内的 `kustomization.yaml` 中指定。
|
||||
|
||||
<!-- #### Generate ConfigMaps from files -->
|
||||
#### 根据文件生成 ConfigMap
|
||||
<!-- For example, to generate a ConfigMap from files `configure-pod-container/configmap/kubectl/game.properties`
|
||||
```shell
|
||||
# Create a kustomization.yaml file with ConfigMapGenerator
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: game-config-4
|
||||
files:
|
||||
- configure-pod-container/configmap/kubectl/game.properties
|
||||
EOF
|
||||
``` -->
|
||||
例如,要从 `configure-pod-container/configmap/kubectl/game.properties` 文件生成一个 ConfigMap
|
||||
```shell
|
||||
# 使用 ConfigMapGenerator 创建 kustomization.yaml 文件
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: game-config-4
|
||||
files:
|
||||
- configure-pod-container/configmap/kubectl/game.properties
|
||||
EOF
|
||||
```
|
||||
|
||||
<!-- Apply the kustomization directory to create the ConfigMap object. -->
|
||||
使用 kustomization 目录创建 ConfigMap 对象
|
||||
```shell
|
||||
kubectl apply -k .
|
||||
configmap/game-config-4-m9dm2f92bt created
|
||||
```
|
||||
|
||||
<!-- You can check that the ConfigMap was created like this: -->
|
||||
您可以检查 ConfigMap 是这样创建的:
|
||||
|
||||
```shell
|
||||
kubectl get configmap
|
||||
NAME DATA AGE
|
||||
game-config-4-m9dm2f92bt 1 37s
|
||||
|
||||
|
||||
kubectl describe configmaps/game-config-4-m9dm2f92bt
|
||||
Name: game-config-4-m9dm2f92bt
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: kubectl.kubernetes.io/last-applied-configuration:
|
||||
{"apiVersion":"v1","data":{"game.properties":"enemies=aliens\nlives=3\nenemies.cheat=true\nenemies.cheat.level=noGoodRotten\nsecret.code.p...
|
||||
|
||||
Data
|
||||
====
|
||||
game.properties:
|
||||
----
|
||||
enemies=aliens
|
||||
lives=3
|
||||
enemies.cheat=true
|
||||
enemies.cheat.level=noGoodRotten
|
||||
secret.code.passphrase=UUDDLRLRBABAS
|
||||
secret.code.allowed=true
|
||||
secret.code.lives=30
|
||||
Events: <none>
|
||||
```
|
||||
|
||||
<!-- Note that the generated ConfigMap name has a suffix appended by hashing the contents. This ensures that a
|
||||
new ConfigMap is generated each time the content is modified. -->
|
||||
请注意,生成的 ConfigMap 名称具有通过对内容进行散列而附加的后缀,这样可以确保每次修改内容时都会生成新的 ConfigMap。
|
||||
|
||||
<!-- #### Define the key to use when generating a ConfigMap from a file -->
|
||||
#### 定义从文件生成 ConfigMap 时要使用的密钥
|
||||
<!-- You can define a key other than the file name to use in the ConfigMap generator.
|
||||
For example, to generate a ConfigMap from files `configure-pod-container/configmap/kubectl/game.properties`
|
||||
with the key `game-special-key` -->
|
||||
您可以定义一个非文件名的键,在 ConfigMap 生成器中使用。例如,使用 `game-special-key` 从 `configure-pod-container / configmap / kubectl / game.properties` 文件生成 ConfigMap。
|
||||
|
||||
<!-- ```shell
|
||||
# Create a kustomization.yaml file with ConfigMapGenerator
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: game-config-5
|
||||
files:
|
||||
- game-special-key=configure-pod-container/configmap/kubectl/game.properties
|
||||
EOF
|
||||
``` -->
|
||||
```shell
|
||||
# 使用 ConfigMapGenerator 创建 kustomization.yaml 文件
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: game-config-5
|
||||
files:
|
||||
- game-special-key=configure-pod-container/configmap/kubectl/game.properties
|
||||
EOF
|
||||
```
|
||||
|
||||
<!-- Apply the kustomization directory to create the ConfigMap object. -->
|
||||
使用 Kustomization 目录创建 ConfigMap 对象。
|
||||
```shell
|
||||
kubectl apply -k .
|
||||
configmap/game-config-5-m67dt67794 created
|
||||
```
|
||||
|
||||
<!-- #### Generate ConfigMaps from Literals -->
|
||||
#### 从文字值生成 ConfigMap
|
||||
<!-- To generate a ConfigMap from literals `special.type=charm` and `special.how=very`,
|
||||
you can specify the ConfigMap generator in `kusotmization.yaml` as -->
|
||||
要从文字 `special.type=charm` 和 `special.how=very` 生成 ConfigMap,可以在 `kusotmization.yaml` 中将 ConfigMap 生成器指定。
|
||||
<!-- ```shell
|
||||
# Create a kustomization.yaml file with ConfigMapGenerator
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: special-config-2
|
||||
literals:
|
||||
- special.how=very
|
||||
- special.type=charm
|
||||
EOF
|
||||
``` -->
|
||||
```shell
|
||||
# 使用 ConfigMapGenerator 创建 kustomization.yaml 文件
|
||||
cat <<EOF >./kustomization.yaml
|
||||
configMapGenerator:
|
||||
- name: special-config-2
|
||||
literals:
|
||||
- special.how=very
|
||||
- special.type=charm
|
||||
EOF
|
||||
```
|
||||
<!-- Apply the kustomization directory to create the ConfigMap object. -->
|
||||
使用 Kustomization 目录创建 ConfigMap 对象。
|
||||
```shell
|
||||
kubectl apply -k .
|
||||
configmap/special-config-2-c92b5mmcf2 created
|
||||
```
|
||||
|
||||
<!-- ## Define container environment variables using ConfigMap data -->
|
||||
## 使用 ConfigMap 数据定义容器环境变量
|
||||
|
||||
<!-- ### Define a container environment variable with data from a single ConfigMap -->
|
||||
### 使用单个 ConfigMap 中的数据定义容器环境变量
|
||||
|
||||
<!-- 1. Define an environment variable as a key-value pair in a ConfigMap: -->
|
||||
1. 在 ConfigMap 中将环境变量定义为键值对:
|
||||
|
||||
```shell
|
||||
kubectl create configmap special-config --from-literal=special.how=very
|
||||
```
|
||||
|
||||
<!-- 2. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY` environment variable in the Pod specification. -->
|
||||
2. 将 ConfigMap 中定义的 `special.how` 值分配给 Pod 规范中的 `SPECIAL_LEVEL_KEY` 环境变量。
|
||||
|
||||
{{< codenew file="pods/pod-single-configmap-env-variable.yaml" >}}
|
||||
|
||||
<!-- Create the Pod: -->
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-single-configmap-env-variable.yaml
|
||||
```
|
||||
|
||||
<!-- Now, the Pod's output includes environment variable `SPECIAL_LEVEL_KEY=very`. -->
|
||||
现在,Pod 的输出包含环境变量 `SPECIAL_LEVEL_KEY=very`。
|
||||
|
||||
<!-- ### Define container environment variables with data from multiple ConfigMaps -->
|
||||
### 使用来自多个 ConfigMap 的数据定义容器环境变量
|
||||
|
||||
<!-- * As with the previous example, create the ConfigMaps first. -->
|
||||
* 与前面的示例一样,首先创建 ConfigMap。
|
||||
|
||||
{{< codenew file="configmap/configmaps.yaml" >}}
|
||||
|
||||
<!-- Create the ConfigMap: -->
|
||||
创建 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/configmap/configmaps.yaml
|
||||
```
|
||||
|
||||
<!-- * Define the environment variables in the Pod specification. -->
|
||||
* 在 Pod 规范中定义环境变量。
|
||||
|
||||
{{< codenew file="pods/pod-multiple-configmap-env-variable.yaml" >}}
|
||||
|
||||
<!-- Create the Pod: -->
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-multiple-configmap-env-variable.yaml
|
||||
```
|
||||
|
||||
<!-- Now, the Pod's output includes environment variables `SPECIAL_LEVEL_KEY=very` and `LOG_LEVEL=INFO`. -->
|
||||
现在,Pod 的输出包含环境变量 `SPECIAL_LEVEL_KEY=very` 和 `LOG_LEVEL=INFO`。
|
||||
|
||||
<!-- ## Configure all key-value pairs in a ConfigMap as container environment variables -->
|
||||
## 将 ConfigMap 中的所有键值对配置为容器环境变量
|
||||
|
||||
{{< note >}}
|
||||
<!-- This functionality is available in Kubernetes v1.6 and later. -->
|
||||
Kubernetes v1.6 和更高版本提供了此功能。
|
||||
{{< /note >}}
|
||||
|
||||
<!-- * Create a ConfigMap containing multiple key-value pairs. -->
|
||||
* 创建一个包含多个键值对的 ConfigMap。
|
||||
|
||||
{{< codenew file="configmap/configmap-multikeys.yaml" >}}
|
||||
|
||||
<!-- Create the ConfigMap: -->
|
||||
创建 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml
|
||||
```
|
||||
|
||||
<!-- * Use `envFrom` to define all of the ConfigMap's data as container environment variables. The key from the ConfigMap becomes the environment variable name in the Pod. -->
|
||||
* 使用 `envFrom` 将所有 ConfigMap 的数据定义为容器环境变量,ConfigMap 中的键成为 Pod 中的环境变量名称。
|
||||
|
||||
{{< codenew file="pods/pod-configmap-envFrom.yaml" >}}
|
||||
|
||||
<!-- Create the Pod: -->
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-envFrom.yaml
|
||||
```
|
||||
|
||||
<!-- Now, the Pod's output includes environment variables `SPECIAL_LEVEL=very` and `SPECIAL_TYPE=charm`. -->
|
||||
现在,Pod 的输出包含环境变量 `SPECIAL_LEVEL=very` 和 `SPECIAL_TYPE=charm`。
|
||||
|
||||
|
||||
<!-- ## Use ConfigMap-defined environment variables in Pod commands -->
|
||||
## 在 Pod 命令中使用 ConfigMap 定义的环境变量
|
||||
|
||||
<!-- You can use ConfigMap-defined environment variables in the `command` section of the Pod specification using the `$(VAR_NAME)` Kubernetes substitution syntax. -->
|
||||
您可以使用 `$(VAR_NAME)` Kubernetes 替换语法在 Pod 规范的 `command` 部分中使用 ConfigMap 定义的环境变量。
|
||||
|
||||
<!-- For example, the following Pod specification -->
|
||||
例如,以下 Pod 规范
|
||||
|
||||
{{< codenew file="pods/pod-configmap-env-var-valueFrom.yaml" >}}
|
||||
|
||||
<!-- created by running -->
|
||||
通过运行创建
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml
|
||||
```
|
||||
|
||||
<!-- produces the following output in the `test-container` container: -->
|
||||
在 `test-container` 容器中产生以下输出:
|
||||
|
||||
```shell
|
||||
very charm
|
||||
```
|
||||
|
||||
<!-- ## Add ConfigMap data to a Volume -->
|
||||
## 将 ConfigMap 数据添加到一个容器中
|
||||
|
||||
<!-- As explained in [Create ConfigMaps from files](#create-configmaps-from-files), when you create a ConfigMap using ``--from-file``, the filename becomes a key stored in the `data` section of the ConfigMap. The file contents become the key's value. -->
|
||||
如[根据文件创建ConfigMap](#create-configmaps-from-files)中所述,当您使用 ``--from-file`` 创建 ConfigMap 时,文件名成为存储在 ConfigMap 的 `data` 部分中的密钥,文件内容成为密钥的值。
|
||||
|
||||
<!-- The examples in this section refer to a ConfigMap named special-config, shown below. -->
|
||||
本节中的示例引用了一个名为 special-config 的 ConfigMap,如下所示:
|
||||
|
||||
{{< codenew file="configmap/configmap-multikeys.yaml" >}}
|
||||
|
||||
<!-- Create the ConfigMap: -->
|
||||
创建 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml
|
||||
```
|
||||
|
||||
<!-- ### Populate a Volume with data stored in a ConfigMap -->
|
||||
### 使用存储在 ConfigMap 中的数据填充容器
|
||||
|
||||
<!-- Add the ConfigMap name under the `volumes` section of the Pod specification.
|
||||
This adds the ConfigMap data to the directory specified as `volumeMounts.mountPath` (in this case, `/etc/config`).
|
||||
The `command` section references the `special.level` item stored in the ConfigMap. -->
|
||||
在 Pod 规范的 `volumes` 部分下添加 ConfigMap 名称。
|
||||
这会将 ConfigMap 数据添加到指定为 `volumeMounts.mountPath` 的目录(在本例中为`/etc/config`)。
|
||||
`command` 引用存储在 ConfigMap 中的 `special.level`。
|
||||
|
||||
{{< codenew file="pods/pod-configmap-volume.yaml" >}}
|
||||
|
||||
<!-- Create the Pod: -->
|
||||
创建Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume.yaml
|
||||
```
|
||||
|
||||
<!-- When the pod runs, the command `ls /etc/config/` produces the output below: -->
|
||||
运行命令 `ls /etc/config/` 产生下面的输出:
|
||||
|
||||
```shell
|
||||
SPECIAL_LEVEL
|
||||
SPECIAL_TYPE
|
||||
```
|
||||
|
||||
{{< caution >}}
|
||||
<!-- If there are some files in the `/etc/config/` directory, they will be deleted. -->
|
||||
如果在 `/etc/config/` 目录中有一些文件,它们将被删除。
|
||||
{{< /caution >}}
|
||||
|
||||
<!-- ### Add ConfigMap data to a specific path in the Volume -->
|
||||
### 将 ConfigMap 数据添加到容器中的特定路径
|
||||
|
||||
<!-- Use the `path` field to specify the desired file path for specific ConfigMap items.
|
||||
In this case, the `SPECIAL_LEVEL` item will be mounted in the `config-volume` volume at `/etc/config/keys`. -->
|
||||
使用 `path` 字段为特定的 ConfigMap 项目指定所需的文件路径。
|
||||
在这种情况下, `SPECIAL_LEVEL` 将安装在 `/etc/config/keys` 目录下的 `config-volume` 容器中。
|
||||
|
||||
{{< codenew file="pods/pod-configmap-volume-specific-key.yaml" >}}
|
||||
|
||||
<!-- Create the Pod: -->
|
||||
创建Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume-specific-key.yaml
|
||||
```
|
||||
|
||||
<!-- When the pod runs, the command `cat /etc/config/keys` produces the output below: -->
|
||||
当 pod 运行时,命令 `cat /etc/config/keys` 产生以下输出:
|
||||
|
||||
```shell
|
||||
very
|
||||
```
|
||||
|
||||
{{< caution >}}
|
||||
<!-- Like before, all previous files in the `/etc/config/` directory will be deleted. -->
|
||||
和以前一样,`/etc/config/` 目录中的所有先前文件都将被删除。
|
||||
{{< /caution >}}
|
||||
|
||||
<!-- ### Project keys to specific paths and file permissions -->
|
||||
### 项目密钥以指定路径和文件权限
|
||||
|
||||
<!-- You can project keys to specific paths and specific permissions on a per-file
|
||||
basis. The [Secrets](/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod) user guide explains the syntax. -->
|
||||
您可以将密钥映射到每个文件的特定路径和特定权限。[Secrets](/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod) 用户指南说明了语法。
|
||||
|
||||
<!-- ### Mounted ConfigMaps are updated automatically -->
|
||||
### 挂载的 ConfigMap 将自动更新
|
||||
|
||||
<!-- When a ConfigMap already being consumed in a volume is updated, projected keys are eventually updated as well. Kubelet is checking whether the mounted ConfigMap is fresh on every periodic sync. However, it is using its local ttl-based cache for getting the current value of the ConfigMap. As a result, the total delay from the moment when the ConfigMap is updated to the moment when new keys are projected to the pod can be as long as kubelet sync period + ttl of ConfigMaps cache in kubelet. -->
|
||||
更新已经在容器中使用的 ConfigMap 时,最终也会更新映射键。Kubelet 实时检查是否在每个定期同步中都更新已安装的 ConfigMap。它使用其基于本地 ttl 的缓存来获取 ConfigMap 的当前值。结果,从更新 ConfigMap 到将新密钥映射到 Pod 的总延迟可以与 ConfigMap 在 kubelet 中缓存的 kubelet 同步周期 ttl 一样长。
|
||||
|
||||
{{< note >}}
|
||||
<!-- A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath) volume will not receive ConfigMap updates. -->
|
||||
使用 ConfigMap 作为子路径[subPath](/docs/concepts/storage/volumes/#using-subpath)的容器将不会收到 ConfigMap 更新。
|
||||
{{< /note >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture discussion %}}
|
||||
|
||||
<!-- ## Understanding ConfigMaps and Pods -->
|
||||
## 了解 ConfigMap 和 Pod
|
||||
|
||||
<!-- The ConfigMap API resource stores configuration data as key-value pairs. The data can be consumed in pods or provide the configurations for system components such as controllers. ConfigMap is similar to [Secrets](/docs/concepts/configuration/secret/), but provides a means of working with strings that don't contain sensitive information. Users and system components alike can store configuration data in ConfigMap. -->
|
||||
ConfigMap API 资源将配置数据存储为键值对。数据可以在 Pod 中使用,也可以提供系统组件(如控制器)的配置。ConfigMap 与 [Secrets](/docs/concepts/configuration/secret/)类似,但是提供了一种使用不包含敏感信息的字符串的方法。用户和系统组件都可以在 ConfigMap 中存储配置数据。
|
||||
|
||||
{{< note >}}
|
||||
<!-- ConfigMaps should reference properties files, not replace them. Think of the ConfigMap as representing something similar to the Linux `/etc` directory and its contents. For example, if you create a [Kubernetes Volume](/docs/concepts/storage/volumes/) from a ConfigMap, each data item in the ConfigMap is represented by an individual file in the volume. -->
|
||||
ConfigMap 应该引用属性文件,而不是替换它们。可以将 ConfigMap 表示为类似于 Linux `/etc` 目录及其内容的东西。例如,如果您从 ConfigMap 创建[Kubernetes Volume](/docs/concepts/storage/volumes/),则 ConfigMap 中的每个数据项都由该容器中的单个文件表示。
|
||||
{{< /note >}}
|
||||
|
||||
<!-- The ConfigMap's `data` field contains the configuration data. As shown in the example below, this can be simple -- like individual properties defined using `--from-literal` -- or complex -- like configuration files or JSON blobs defined using `--from-file`. -->
|
||||
ConfigMap 的 `data` 字段包含配置数据。如下例所示,它可以很简单 -- 就像使用 `--from-literal` -- 定义的单个属性一样,也可以很复杂 -- 例如使用 `--from-file` 定义的配置文件或 JSON blob。
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
creationTimestamp: 2016-02-18T19:14:38Z
|
||||
name: example-config
|
||||
namespace: default
|
||||
data:
|
||||
# example of a simple property defined using --from-literal
|
||||
example.property.1: hello
|
||||
example.property.2: world
|
||||
# example of a complex property defined using --from-file
|
||||
example.property.file: |-
|
||||
property.1=value-1
|
||||
property.2=value-2
|
||||
property.3=value-3
|
||||
```
|
||||
|
||||
<!-- ### Restrictions -->
|
||||
### 限制规定
|
||||
|
||||
<!-- - You must create a ConfigMap before referencing it in a Pod specification (unless you mark the ConfigMap as "optional"). If you reference a ConfigMap that doesn't exist, the Pod won't start. Likewise, references to keys that don't exist in the ConfigMap will prevent the pod from starting. -->
|
||||
- 在 Pod 规范中引用它之前,必须先创建一个 ConfigMap(除非将 ConfigMap 标记为"可选")。如果引用的 ConfigMap 不存在,则 Pod 将不会启动。同样,对 ConfigMap 中不存在的键的引用将阻止容器启动。
|
||||
|
||||
<!-- - If you use `envFrom` to define environment variables from ConfigMaps, keys that are considered invalid will be skipped. The pod will be allowed to start, but the invalid names will be recorded in the event log (`InvalidVariableNames`). The log message lists each skipped key. For example: -->
|
||||
- 如果您使用 `envFrom` 从 ConfigMap 中定义环境变量,那么将忽略被认为无效的键。可以启动 Pod,但无效名称将记录在事件日志中(InvalidVariableNames)。日志消息列出了每个跳过的键。例如:
|
||||
|
||||
```shell
|
||||
kubectl get events
|
||||
```
|
||||
|
||||
<!-- The output is similar to this: -->
|
||||
输出与此类似:
|
||||
```
|
||||
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE
|
||||
0s 0s 1 dapi-test-pod Pod Warning InvalidEnvironmentVariableNames {kubelet, 127.0.0.1} Keys [1badkey, 2alsobad] from the EnvFrom configMap default/myconfig were skipped since they are considered invalid environment variable names.
|
||||
```
|
||||
|
||||
<!-- - ConfigMaps reside in a specific [namespace](/docs/concepts/overview/working-with-objects/namespaces/). A ConfigMap can only be referenced by pods residing in the same namespace. -->
|
||||
- ConfigMaps reside in a specific [命令空间](/docs/concepts/overview/working-with-objects/namespaces/). A ConfigMap can only be referenced by pods residing in the same namespace.
|
||||
ConfigMap 驻留在特定的[命令空间](/docs/concepts/overview/working-with-objects/namespaces/)中。ConfigMap 只能由位于相同命令空间中的 Pod 引用。
|
||||
|
||||
<!-- - Kubelet doesn't support the use of ConfigMaps for pods not found on the API server. This includes pods created via the Kubelet's `--manifest-url` flag, `--config` flag, or the Kubelet REST API. -->
|
||||
- Kubelet 不支持将 ConfigMap 用于未在 API 服务器上找到的 Pod。这包括通过 Kubelet 的 `--manifest-url` 参数,`--config` 参数或者 Kubelet REST API 创建的容器。
|
||||
|
||||
{{< note >}}
|
||||
<!-- These are not commonly-used ways to create pods. -->
|
||||
这些不是创建 pods 的常用方法。
|
||||
{{< /note >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
<!-- * Follow a real world example of [Configuring Redis using a ConfigMap](/docs/tutorials/configuration/configure-redis-using-configmap/). -->
|
||||
* 遵循[使用ConfigMap配置Redis](/docs/tutorials/configuration/configure-redis-using-configmap/)的真实案例。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
title: 配置 Pod 初始化
|
||||
content_template: templates/task
|
||||
weight: 130
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: Configure Pod Initialization
|
||||
content_template: templates/task
|
||||
weight: 130
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
<!--
|
||||
This page shows how to use an Init Container to initialize a Pod before an
|
||||
application Container runs.
|
||||
-->
|
||||
本文介绍在应用容器运行前,怎样利用 Init 容器初始化 Pod。
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Create a Pod that has an Init Container
|
||||
|
||||
In this exercise you create a Pod that has one application Container and one
|
||||
Init Container. The init container runs to completion before the application
|
||||
container starts.
|
||||
|
||||
Here is the configuration file for the Pod:
|
||||
-->
|
||||
|
||||
## 创建一个包含 Init 容器的 Pod
|
||||
|
||||
本例中您将创建一个包含一个应用容器和一个 Init 容器的 Pod。Init 容器在应用容器启动前运行完成。
|
||||
|
||||
下面是 Pod 的配置文件:
|
||||
|
||||
{{< codenew file="pods/init-containers.yaml" >}}
|
||||
|
||||
<!--
|
||||
In the configuration file, you can see that the Pod has a Volume that the init
|
||||
container and the application container share.
|
||||
|
||||
The init container mounts the
|
||||
shared Volume at `/work-dir`, and the application container mounts the shared
|
||||
Volume at `/usr/share/nginx/html`. The init container runs the following command
|
||||
and then terminates:
|
||||
-->
|
||||
|
||||
配置文件中,您可以看到应用容器和 Init 容器共享了一个卷。
|
||||
|
||||
Init 容器将共享卷挂载到了 `/work-dir` 目录,应用容器将共享卷挂载到了 `/usr/share/nginx/html` 目录。
|
||||
Init 容器执行完下面的命令就终止:
|
||||
|
||||
wget -O /work-dir/index.html http://kubernetes.io
|
||||
|
||||
<!--
|
||||
Notice that the init container writes the `index.html` file in the root directory
|
||||
of the nginx server.
|
||||
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
请注意 Init 容器在 nginx 服务器的根目录写入 `index.html`。
|
||||
|
||||
创建 Pod:
|
||||
|
||||
kubectl create -f https://k8s.io/examples/pods/init-containers.yaml
|
||||
|
||||
<!--
|
||||
Verify that the nginx container is running:
|
||||
-->
|
||||
|
||||
检查 nginx 容器运行正常:
|
||||
|
||||
kubectl get pod init-demo
|
||||
|
||||
<!--
|
||||
The output shows that the nginx container is running:
|
||||
-->
|
||||
|
||||
结果表明 nginx 容器运行正常:
|
||||
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
init-demo 1/1 Running 0 1m
|
||||
|
||||
<!--
|
||||
Get a shell into the nginx container running in the init-demo Pod:
|
||||
-->
|
||||
|
||||
通过 shell 进入 init-demo Pod 中的 nginx 容器:
|
||||
|
||||
kubectl exec -it init-demo -- /bin/bash
|
||||
|
||||
<!--
|
||||
In your shell, send a GET request to the nginx server:
|
||||
-->
|
||||
|
||||
在 shell 中,发送个 GET 请求到 nginx 服务器:
|
||||
|
||||
root@nginx:~# apt-get update
|
||||
root@nginx:~# apt-get install curl
|
||||
root@nginx:~# curl localhost
|
||||
|
||||
<!--
|
||||
The output shows that nginx is serving the web page that was written by the init container:
|
||||
-->
|
||||
|
||||
结果表明 nginx 正在为 Init 容器编写的 web 页面服务:
|
||||
|
||||
<!Doctype html>
|
||||
<html id="home">
|
||||
|
||||
<head>
|
||||
...
|
||||
"url": "http://kubernetes.io/"}</script>
|
||||
</head>
|
||||
<body>
|
||||
...
|
||||
<p>Kubernetes is open source giving you the freedom to take advantage ...</p>
|
||||
...
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
* Learn more about
|
||||
[communicating between Containers running in the same Pod](/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/).
|
||||
* Learn more about [Init Containers](/docs/concepts/workloads/pods/init-containers/).
|
||||
* Learn more about [Volumes](/docs/concepts/storage/volumes/).
|
||||
* Learn more about [Debugging Init Containers](/docs/tasks/debug-application-cluster/debug-init-containers/)
|
||||
-->
|
||||
|
||||
* 进一步了解 [相同 Pod 中的容器间的通信](/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/)。
|
||||
* 进一步了解 [Init 容器](/docs/concepts/workloads/pods/init-containers/)。
|
||||
* 进一步了解 [卷](/docs/concepts/storage/volumes/)。
|
||||
* 进一步了解 [Init 容器排错](/docs/tasks/debug-application-cluster/debug-init-containers/)。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
reviewers:
|
||||
- jpeeler
|
||||
- pmorie
|
||||
title: 配置 Pod 使用投射卷作存储
|
||||
content_template: templates/task
|
||||
weight: 70
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
reviewers:
|
||||
- jpeeler
|
||||
- pmorie
|
||||
title: Configure a Pod to Use a Projected Volume for Storage
|
||||
content_template: templates/task
|
||||
weight: 70
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
<!--
|
||||
This page shows how to use a [`projected`](/docs/concepts/storage/volumes/#projected) volume to mount
|
||||
several existing volume sources into the same directory. Currently, `secret`, `configMap`, `downwardAPI`,
|
||||
and `serviceAccountToken` volumes can be projected.
|
||||
-->
|
||||
|
||||
本文介绍怎样通过[`投射`](/docs/concepts/storage/volumes/#projected) 卷将现有的多个卷资源挂载到相同的目录。
|
||||
当前,`secret`、`configMap`、`downwardAPI` 和 `serviceAccountToken` 卷可以被投射。
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
`serviceAccountToken` is not a volume type.
|
||||
-->
|
||||
`serviceAccountToken` 不是一种卷类型
|
||||
{{< /note >}}
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Configure a projected volume for a pod
|
||||
|
||||
In this exercise, you create username and password Secrets from local files. You then create a Pod that runs one Container, using a [`projected`](/docs/concepts/storage/volumes/#projected) Volume to mount the Secrets into the same shared directory.
|
||||
|
||||
Here is the configuration file for the Pod:
|
||||
-->
|
||||
|
||||
## 为 Pod 配置投射卷
|
||||
|
||||
本练习中,您将从本地文件来创建包含有用户名和密码的 Secret。然后创建运行一个容器的 Pod,该 Pod 使用[`投射`](/docs/concepts/storage/volumes/#projected) 卷将 Secret 挂载到相同的路径下。
|
||||
|
||||
下面是 Pod 的配置文件:
|
||||
|
||||
{{< codenew file="pods/storage/projected.yaml" >}}
|
||||
|
||||
1. <!--Create the Secrets:-->创建 Secrets:
|
||||
```shell
|
||||
<!--# Create files containing the username and password:--># 创建包含用户名和密码的文件:
|
||||
echo -n "admin" > ./username.txt
|
||||
echo -n "1f2d1e2e67df" > ./password.txt-->
|
||||
|
||||
<!--# Package these files into secrets:--># 将上述文件引用到 Secret:
|
||||
kubectl create secret generic user --from-file=./username.txt
|
||||
kubectl create secret generic pass --from-file=./password.txt
|
||||
```
|
||||
|
||||
1. <!--Create the Pod:-->创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/storage/projected.yaml
|
||||
```
|
||||
|
||||
<!--Verify that the Pod's Container is running, and then watch for changes to
|
||||
the Pod:-->确认 Pod 中的容器运行正常,然后监视 Pod 的变化:
|
||||
|
||||
```shell
|
||||
kubectl get --watch pod test-projected-volume
|
||||
```
|
||||
|
||||
<!--The output looks like this:-->输出结果和下面类似:
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
test-projected-volume 1/1 Running 0 14s
|
||||
|
||||
1. <!--In another terminal, get a shell to the running Container:-->在另外一个终端中,打开容器的 shell:
|
||||
```shell
|
||||
kubectl exec -it test-projected-volume -- /bin/sh
|
||||
```
|
||||
|
||||
1. <!--In your shell, verify that the `projected-volume` directory contains your projected sources:-->在 shell 中,确认 `projected-volume` 目录包含你的投射源:
|
||||
```shell
|
||||
ls /projected-volume/
|
||||
```
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
* Learn more about [`projected`](/docs/concepts/storage/volumes/#projected) volumes.
|
||||
* Read the [all-in-one volume](https://github.com/kubernetes/community/blob/{{< param "githubbranch" >}}/contributors/design-proposals/node/all-in-one-volume.md) design document.
|
||||
-->
|
||||
|
||||
* 进一步了解[`投射`](/docs/concepts/storage/volumes/#projected) 卷。
|
||||
* 阅读[一体卷](https://github.com/kubernetes/community/blob/{{< param "githubbranch" >}}/contributors/design-proposals/node/all-in-one-volume.md)设计文档。
|
||||
{{% /capture %}}
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
---
|
||||
reviewers:
|
||||
- bprashanth
|
||||
- liggitt
|
||||
- thockin
|
||||
title: 为 Pod 配置服务账户
|
||||
content_template: templates/task
|
||||
weight: 90
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
reviewers:
|
||||
- bprashanth
|
||||
- liggitt
|
||||
- thockin
|
||||
title: Configure Service Accounts for Pods
|
||||
content_template: templates/task
|
||||
weight: 90
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
A service account provides an identity for processes that run in a Pod.
|
||||
|
||||
*This is a user introduction to Service Accounts. See also the
|
||||
[Cluster Admin Guide to Service Accounts](/docs/reference/access-authn-authz/service-accounts-admin/).*
|
||||
-->
|
||||
|
||||
服务账户为 Pod 中运行的进程提供了一个标识。
|
||||
|
||||
*本文是服务账户的用户使用介绍。您也可以参考[集群管理指南之服务账户](/docs/reference/access-authn-authz/service-accounts-admin/)。*
|
||||
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
This document describes how service accounts behave in a cluster set up
|
||||
as recommended by the Kubernetes project. Your cluster administrator may have
|
||||
customized the behavior in your cluster, in which case this documentation may
|
||||
not apply.
|
||||
-->
|
||||
|
||||
本文档描述 Kubernetes 项目推荐的集群中服务帐户的行为。
|
||||
集群管理员也可能已经定制了服务账户在集群中的属性,在这种情况下,本文档可能并不适用。
|
||||
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
When you (a human) access the cluster (for example, using `kubectl`), you are
|
||||
authenticated by the apiserver as a particular User Account (currently this is
|
||||
usually `admin`, unless your cluster administrator has customized your
|
||||
cluster). Processes in containers inside pods can also contact the apiserver.
|
||||
When they do, they are authenticated as a particular Service Account (for example,
|
||||
`default`).
|
||||
-->
|
||||
|
||||
当您(人类)访问集群时(例如,使用 `kubectl`),api 服务器将您的身份验证为特定的用户帐户(当前这通常是 `admin`,除非您的集群管理员已经定制了您的集群配置)。
|
||||
Pod 内的容器中的进程也可以与 api 服务器接触。
|
||||
当它们进行身份验证时,它们被验证为特定的服务帐户(例如,`default`)。
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Use the Default Service Account to access the API server.
|
||||
|
||||
When you create a pod, if you do not specify a service account, it is
|
||||
automatically assigned the `default` service account in the same namespace.
|
||||
If you get the raw json or yaml for a pod you have created (for example, `kubectl get pods/podname -o yaml`),
|
||||
you can see the `spec.serviceAccountName` field has been
|
||||
[automatically set](/docs/user-guide/working-with-resources/#resources-are-automatically-modified).
|
||||
-->
|
||||
|
||||
## 使用默认的服务账户访问 API 服务器
|
||||
|
||||
当您创建 Pod 时,如果没有指定服务账户,Pod 会被指定命名空间中的`default`服务账户。
|
||||
如果您查看 Pod 的原始 json 或 yaml(例如:`kubectl get pods/podname -o yaml`),
|
||||
您可以看到 `spec.serviceAccountName` 字段已经被[自动设置](/docs/user-guide/working-with-resources/#resources-are-automatically-modified)了。
|
||||
|
||||
<!--
|
||||
You can access the API from inside a pod using automatically mounted service account credentials,
|
||||
as described in [Accessing the Cluster](/docs/user-guide/accessing-the-cluster/#accessing-the-api-from-a-pod).
|
||||
The API permissions of the service account depend on the [authorization plugin and policy](/docs/reference/access-authn-authz/authorization/#authorization-modules) in use.
|
||||
|
||||
In version 1.6+, you can opt out of automounting API credentials for a service account by setting
|
||||
`automountServiceAccountToken: false` on the service account:
|
||||
-->
|
||||
|
||||
您可以使用自动挂载给 Pod 的服务账户凭据访问 API,[访问集群](/docs/user-guide/accessing-the-cluster/#accessing-the-api-from-a-pod) 中有相关描述。
|
||||
服务账户的 API 许可取决于您所使用的[授权插件和策略](/docs/reference/access-authn-authz/authorization/#authorization-modules)。
|
||||
|
||||
在 1.6 以上版本中,您可以通过在服务账户上设置 `automountServiceAccountToken: false` 来实现不给服务账号自动挂载 API 凭据:
|
||||
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: build-robot
|
||||
automountServiceAccountToken: false
|
||||
...
|
||||
```
|
||||
|
||||
<!--
|
||||
In version 1.6+, you can also opt out of automounting API credentials for a particular pod:
|
||||
-->
|
||||
|
||||
在 1.6 以上版本中,您也可以选择不给特定 Pod 自动挂载 API 凭据:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: my-pod
|
||||
spec:
|
||||
serviceAccountName: build-robot
|
||||
automountServiceAccountToken: false
|
||||
...
|
||||
```
|
||||
|
||||
<!--
|
||||
The pod spec takes precedence over the service account if both specify a `automountServiceAccountToken` value.
|
||||
|
||||
## Use Multiple Service Accounts.
|
||||
|
||||
Every namespace has a default service account resource called `default`.
|
||||
You can list this and any other serviceAccount resources in the namespace with this command:
|
||||
-->
|
||||
|
||||
如果 Pod 和服务账户都指定了 `automountServiceAccountToken` 值,则 Pod 的 spec 优先于服务帐户。
|
||||
|
||||
## 使用多个服务账户
|
||||
|
||||
每个命名空间都有一个名为 `default` 的服务账户资源。
|
||||
您可以用下面的命令查询这个服务账户以及命名空间中的其他 serviceAccount 资源:
|
||||
|
||||
```shell
|
||||
kubectl get serviceAccounts
|
||||
NAME SECRETS AGE
|
||||
default 1 1d
|
||||
```
|
||||
|
||||
<!--
|
||||
You can create additional ServiceAccount objects like this:
|
||||
-->
|
||||
|
||||
您可以像这样来创建额外的 ServiceAccount 对象:
|
||||
|
||||
```shell
|
||||
kubectl create -f - <<EOF
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: build-robot
|
||||
EOF
|
||||
serviceaccount/build-robot created
|
||||
```
|
||||
|
||||
<!--
|
||||
If you get a complete dump of the service account object, like this:
|
||||
-->
|
||||
|
||||
如果您查询服务帐户对象的完整信息,如下所示:
|
||||
|
||||
```shell
|
||||
kubectl get serviceaccounts/build-robot -o yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
creationTimestamp: 2015-06-16T00:12:59Z
|
||||
name: build-robot
|
||||
namespace: default
|
||||
resourceVersion: "272500"
|
||||
uid: 721ab723-13bc-11e5-aec2-42010af0021e
|
||||
secrets:
|
||||
- name: build-robot-token-bvbk5
|
||||
```
|
||||
|
||||
<!--
|
||||
then you will see that a token has automatically been created and is referenced by the service account.
|
||||
|
||||
You may use authorization plugins to [set permissions on service accounts](/docs/reference/access-authn-authz/rbac/#service-account-permissions).
|
||||
|
||||
To use a non-default service account, simply set the `spec.serviceAccountName`
|
||||
field of a pod to the name of the service account you wish to use.
|
||||
-->
|
||||
|
||||
那么您就能看到系统已经自动创建了一个令牌并且被服务账户所引用。
|
||||
|
||||
您可以使用授权插件来 [设置服务账户的访问许可](/docs/reference/access-authn-authz/rbac/#service-account-permissions)。
|
||||
|
||||
要使用非默认的服务账户,只需简单的将 Pod 的 `spec.serviceAccountName` 字段设置为您想用的服务账户名称。
|
||||
|
||||
<!--
|
||||
The service account has to exist at the time the pod is created, or it will be rejected.
|
||||
|
||||
You cannot update the service account of an already created pod.
|
||||
|
||||
You can clean up the service account from this example like this:
|
||||
-->
|
||||
|
||||
Pod 被创建时服务账户必须存在,否则会被拒绝。
|
||||
|
||||
您不能更新已经创建好的 Pod 的服务账户。
|
||||
|
||||
您可以清除服务账户,如下所示:
|
||||
|
||||
```shell
|
||||
kubectl delete serviceaccount/build-robot
|
||||
```
|
||||
|
||||
<!--
|
||||
## Manually create a service account API token.
|
||||
|
||||
Suppose we have an existing service account named "build-robot" as mentioned above, and we create
|
||||
a new secret manually.
|
||||
-->
|
||||
|
||||
## 手动创建服务账户 API 令牌
|
||||
|
||||
假设我们有一个上面提到的名为 "build-robot" 的服务账户,然后我们手动创建一个新的 Secret。
|
||||
|
||||
```shell
|
||||
kubectl create -f - <<EOF
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: build-robot-secret
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: build-robot
|
||||
type: kubernetes.io/service-account-token
|
||||
EOF
|
||||
secret/build-robot-secret created
|
||||
```
|
||||
|
||||
<!--
|
||||
Now you can confirm that the newly built secret is populated with an API token for the "build-robot" service account.
|
||||
|
||||
Any tokens for non-existent service accounts will be cleaned up by the token controller.
|
||||
-->
|
||||
|
||||
现在,您可以确认新构建的 Secret 中填充了 "build-robot" 服务帐户的 API 令牌。
|
||||
|
||||
令牌控制器将清理不存在的服务帐户的所有令牌。
|
||||
|
||||
```shell
|
||||
kubectl describe secrets/build-robot-secret
|
||||
Name: build-robot-secret
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: kubernetes.io/service-account.name=build-robot
|
||||
kubernetes.io/service-account.uid=da68f9c6-9d26-11e7-b84e-002dc52800da
|
||||
|
||||
Type: kubernetes.io/service-account-token
|
||||
|
||||
Data
|
||||
====
|
||||
ca.crt: 1338 bytes
|
||||
namespace: 7 bytes
|
||||
token: ...
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
The content of `token` is elided here.
|
||||
-->
|
||||
这里省略了 `token` 的内容。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Add ImagePullSecrets to a service account
|
||||
|
||||
First, create an imagePullSecret, as described [here](/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod).
|
||||
Next, verify it has been created. For example:
|
||||
-->
|
||||
|
||||
## 为服务账户添加 ImagePullSecrets
|
||||
|
||||
首先,创建一个 ImagePullSecrets,可以参考[这里](/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) 的描述。
|
||||
然后,确认创建是否成功。例如:
|
||||
|
||||
```shell
|
||||
kubectl get secrets myregistrykey
|
||||
NAME TYPE DATA AGE
|
||||
myregistrykey kubernetes.io/.dockerconfigjson 1 1d
|
||||
```
|
||||
<!--
|
||||
Next, modify the default service account for the namespace to use this secret as an imagePullSecret.
|
||||
-->
|
||||
|
||||
接着修改命名空间的默认服务帐户,以将该 Secret 用作 imagePullSecret。
|
||||
|
||||
```shell
|
||||
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "myregistrykey"}]}'
|
||||
```
|
||||
|
||||
<!--
|
||||
Interactive version requiring manual edit:
|
||||
-->
|
||||
|
||||
需要手动编辑的交互式版本:
|
||||
|
||||
```shell
|
||||
kubectl get serviceaccounts default -o yaml > ./sa.yaml
|
||||
|
||||
cat sa.yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
creationTimestamp: 2015-08-07T22:02:39Z
|
||||
name: default
|
||||
namespace: default
|
||||
resourceVersion: "243024"
|
||||
uid: 052fb0f4-3d50-11e5-b066-42010af0d7b6
|
||||
secrets:
|
||||
- name: default-token-uudge
|
||||
|
||||
vi sa.yaml
|
||||
[editor session not shown]
|
||||
[delete line with key "resourceVersion"]
|
||||
[add lines with "imagePullSecrets:"]
|
||||
|
||||
cat sa.yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
creationTimestamp: 2015-08-07T22:02:39Z
|
||||
name: default
|
||||
namespace: default
|
||||
uid: 052fb0f4-3d50-11e5-b066-42010af0d7b6
|
||||
secrets:
|
||||
- name: default-token-uudge
|
||||
imagePullSecrets:
|
||||
- name: myregistrykey
|
||||
|
||||
kubectl replace serviceaccount default -f ./sa.yaml
|
||||
serviceaccounts/default
|
||||
```
|
||||
|
||||
<!--
|
||||
Now, any new pods created in the current namespace will have this added to their spec:
|
||||
-->
|
||||
|
||||
现在,在当前命名空间中创建的每个新 Pod 的 spec 中都会添加下面的内容:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: myregistrykey
|
||||
```
|
||||
|
||||
<!--## Adding Secrets to a service account.
|
||||
|
||||
TODO: Test and explain how to use additional non-K8s secrets with an existing service account.
|
||||
-->
|
||||
|
||||
<!--
|
||||
## Service Account Token Volume Projection
|
||||
-->
|
||||
|
||||
## 服务帐户令牌卷投影
|
||||
|
||||
{{< feature-state for_k8s_version="v1.12" state="beta" >}}
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
This ServiceAccountTokenVolumeProjection is __beta__ in 1.12 and
|
||||
enabled by passing all of the following flags to the API server:
|
||||
|
||||
* `--service-account-issuer`
|
||||
* `--service-account-signing-key-file`
|
||||
* `--service-account-api-audiences`
|
||||
-->
|
||||
|
||||
ServiceAccountTokenVolumeProjection 在 1.12 版本中是 __beta__ 阶段,可以通过向 API 服务器传递以下所有参数来启用它:
|
||||
|
||||
* `--service-account-issuer`
|
||||
* `--service-account-signing-key-file`
|
||||
* `--service-account-api-audiences`
|
||||
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
The kubelet can also project a service account token into a Pod. You can
|
||||
specify desired properties of the token, such as the audience and the validity
|
||||
duration. These properties are not configurable on the default service account
|
||||
token. The service account token will also become invalid against the API when
|
||||
the Pod or the ServiceAccount is deleted.
|
||||
-->
|
||||
|
||||
kubelet 还可以将服务帐户令牌投影到 Pod 中。
|
||||
您可以指定令牌的所需属性,例如受众和有效持续时间。
|
||||
这些属性在默认服务帐户令牌上无法配置。
|
||||
当删除 Pod 或 ServiceAccount 时,服务帐户令牌也将对 API 无效。
|
||||
|
||||
<!--
|
||||
This behavior is configured on a PodSpec using a ProjectedVolume type called
|
||||
[ServiceAccountToken](/docs/concepts/storage/volumes/#projected). To provide a
|
||||
pod with a token with an audience of "vault" and a validity duration of two
|
||||
hours, you would configure the following in your PodSpec:
|
||||
-->
|
||||
|
||||
使用名为 [ServiceAccountToken](/docs/concepts/storage/volumes/#projected) 的 ProjectedVolume 类型在 PodSpec 上配置此功能。
|
||||
要向 Pod 提供具有 "vault" 观众以及两个小时有效期的令牌,可以在 PodSpec 中配置以下内容:
|
||||
|
||||
```yaml
|
||||
kind: Pod
|
||||
apiVersion: v1
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx
|
||||
volumeMounts:
|
||||
- mountPath: /var/run/secrets/tokens
|
||||
name: vault-token
|
||||
volumes:
|
||||
- name: vault-token
|
||||
projected:
|
||||
sources:
|
||||
- serviceAccountToken:
|
||||
path: vault-token
|
||||
expirationSeconds: 7200
|
||||
audience: vault
|
||||
```
|
||||
|
||||
<!--
|
||||
The kubelet will request and store the token on behalf of the pod, make the
|
||||
token available to the pod at a configurable file path, and refresh the token as
|
||||
it approaches expiration. Kubelet proactively rotates the token if it is older
|
||||
than 80% of its total TTL, or if the token is older than 24 hours.
|
||||
|
||||
The application is responsible for reloading the token when it rotates. Periodic
|
||||
reloading (e.g. once every 5 minutes) is sufficient for most usecases.
|
||||
-->
|
||||
|
||||
Kubelet 将代表 Pod 请求和存储令牌,使令牌在可配置的文件路径上对 Pod 可用,并在令牌接近到期时刷新令牌。
|
||||
如果令牌存活时间大于其总 TTL 的 80% 或者大于 24 小时,Kubelet 则会主动旋转令牌。
|
||||
|
||||
应用程序负责在令牌旋转时重新加载令牌。
|
||||
对于大多数情况,定期重新加载(例如,每 5 分钟一次)就足够了。
|
||||
|
||||
{{% /capture %}}
|
||||
@@ -0,0 +1,200 @@
|
||||
---
|
||||
title: 配置 Pod 以使用卷进行存储
|
||||
content_template: templates/task
|
||||
weight: 50
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: Configure a Pod to Use a Volume for Storage
|
||||
content_template: templates/task
|
||||
weight: 50
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
此页面展示了如何配置 Pod 以使用卷进行存储。
|
||||
|
||||
只要容器存在,容器的文件系统就会存在,因此当一个容器终止并重新启动,对该容器的文件系统改动将丢失。对于独立于容器的持久化存储,您可以使用[卷](/docs/concepts/storage/volumes/)。这对于有状态应用程序尤为重要,例如键值存储(如 Redis)和数据库。
|
||||
|
||||
<!--
|
||||
This page shows how to configure a Pod to use a Volume for storage.
|
||||
|
||||
A Container's file system lives only as long as the Container does. So when a
|
||||
Container terminates and restarts, filesystem changes are lost. For more
|
||||
consistent storage that is independent of the Container, you can use a
|
||||
[Volume](/docs/concepts/storage/volumes/). This is especially important for stateful
|
||||
applications, such as key-value stores (such as Redis) and databases.
|
||||
-->
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## 为 Pod 配置卷
|
||||
|
||||
在本练习中,您将创建一个运行 Pod,该 Pod 仅运行一个容器并拥有一个类型为 [emptyDir](/docs/concepts/storage/volumes/#emptydir) 的卷,在整个 Pod 生命周期中一直存在,即使 Pod 中的容器被终止和重启。以下是 Pod 的配置:
|
||||
<!--
|
||||
## Configure a volume for a Pod
|
||||
|
||||
In this exercise, you create a Pod that runs one Container. This Pod has a
|
||||
Volume of type
|
||||
[emptyDir](/docs/concepts/storage/volumes/#emptydir)
|
||||
that lasts for the life of the Pod, even if the Container terminates and
|
||||
restarts. Here is the configuration file for the Pod:
|
||||
-->
|
||||
{{< codenew file="pods/storage/redis.yaml" >}}
|
||||
|
||||
1. 创建 Pod:
|
||||
<!--
|
||||
1.Create the Pod:
|
||||
-->
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/storage/redis.yaml
|
||||
```
|
||||
|
||||
1. 验证 Pod 中的容器是否正在运行,然后留意 Pod 的更改:
|
||||
<!--
|
||||
1.Verify that the Pod's Container is running, and then watch for changes to
|
||||
the Pod:
|
||||
-->
|
||||
|
||||
```shell
|
||||
kubectl get pod redis --watch
|
||||
```
|
||||
|
||||
输出如下:
|
||||
|
||||
```shell
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
redis 1/1 Running 0 13s
|
||||
```
|
||||
|
||||
1. 在另一个终端,用 shell 连接正在运行的容器:
|
||||
<!--
|
||||
1.In another terminal, get a shell to the running Container:
|
||||
-->
|
||||
|
||||
```shell
|
||||
kubectl exec -it redis -- /bin/bash
|
||||
```
|
||||
|
||||
1. 在您的 shell 终端中,切换到 `/data/redis` 目录下,然后创建一个文件:
|
||||
<!--
|
||||
1.In your shell, go to `/data/redis`, and then create a file:
|
||||
-->
|
||||
|
||||
```shell
|
||||
root@redis:/data# cd /data/redis/
|
||||
root@redis:/data/redis# echo Hello > test-file
|
||||
```
|
||||
|
||||
1. 在您的 shell 终端中,列出正在运行的进程:
|
||||
<!--
|
||||
1.In your shell, list the running processes:
|
||||
-->
|
||||
|
||||
```shell
|
||||
root@redis:/data/redis# apt-get update
|
||||
root@redis:/data/redis# apt-get install procps
|
||||
root@redis:/data/redis# ps aux
|
||||
```
|
||||
|
||||
输出类似于:
|
||||
|
||||
```shell
|
||||
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
||||
redis 1 0.1 0.1 33308 3828 ? Ssl 00:46 0:00 redis-server *:6379
|
||||
root 12 0.0 0.0 20228 3020 ? Ss 00:47 0:00 /bin/bash
|
||||
root 15 0.0 0.0 17500 2072 ? R+ 00:48 0:00 ps aux
|
||||
```
|
||||
|
||||
1. 在您的 shell 终端中,结束 Redis 进程:
|
||||
<!--
|
||||
1.In your shell, kill the Redis process:
|
||||
-->
|
||||
|
||||
```shell
|
||||
root@redis:/data/redis# kill <pid>
|
||||
```
|
||||
|
||||
其中 `<pid>` 是 Redis 进程的 ID (PID)。
|
||||
|
||||
1. 在您原先终端中,留意 Redis Pod 的更改。最终您将会看到和下面类似的输出:
|
||||
<!--
|
||||
1. In your original terminal, watch for changes to the Redis Pod. Eventually,
|
||||
you will see something like this:
|
||||
-->
|
||||
|
||||
```shell
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
redis 1/1 Running 0 13s
|
||||
redis 0/1 Completed 0 6m
|
||||
redis 1/1 Running 1 6m
|
||||
```
|
||||
|
||||
此时,容器已经终止并重新启动。这是因为 Redis Pod 的 [restartPolicy](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core) 为 `Always`。
|
||||
<!--
|
||||
At this point, the Container has terminated and restarted. This is because the
|
||||
Redis Pod has a
|
||||
[restartPolicy](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
|
||||
of `Always`.
|
||||
-->
|
||||
|
||||
1. 用 shell 终端进入重新启动的容器中:
|
||||
|
||||
<!--
|
||||
1.Get a shell into the restarted Container:
|
||||
-->
|
||||
```shell
|
||||
kubectl exec -it redis -- /bin/bash
|
||||
```
|
||||
|
||||
1. 在您的 shell 终端中,进入到 `/data/redis` 目录下,并确认 `test-file` 文件是否仍然存在。
|
||||
<!--
|
||||
1.In your shell, goto `/data/redis`, and verify that `test-file` is still there.
|
||||
-->
|
||||
```shell
|
||||
root@redis:/data/redis# cd /data/redis/
|
||||
root@redis:/data/redis# ls
|
||||
test-file
|
||||
```
|
||||
|
||||
1. 删除为此练习所创建的 Pod:
|
||||
|
||||
<!--
|
||||
1.Delete the Pod that you created for this exercise:
|
||||
-->
|
||||
```shell
|
||||
kubectl delete pod redis
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
* 参阅[卷](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)。
|
||||
|
||||
* 参阅 [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)。
|
||||
|
||||
* 除了 `emptyDir` 提供的本地磁盘存储外,Kubernetes 还支持许多不同的网络附加存储解决方案,包括 GCE 上的 PD 和 EC2 上的 EBS,它们是关键数据的首选,并将处理节点上的一些细节,例如安装和卸载设备。了解更多详情请参阅[卷](/docs/concepts/storage/volumes/)。
|
||||
<!--
|
||||
* See [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core).
|
||||
|
||||
* See [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core).
|
||||
|
||||
* In addition to the local disk storage provided by `emptyDir`, Kubernetes
|
||||
supports many different network-attached storage solutions, including PD on
|
||||
GCE and EBS on EC2, which are preferred for critical data and will handle
|
||||
details such as mounting and unmounting the devices on the nodes. See
|
||||
[Volumes](/docs/concepts/storage/volumes/) for more details.
|
||||
-->
|
||||
|
||||
{{% /capture %}}
|
||||
@@ -0,0 +1,221 @@
|
||||
---
|
||||
title: 为容器分派扩展资源
|
||||
content_template: templates/task
|
||||
weight: 40
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: Assign Extended Resources to a Container
|
||||
content_template: templates/task
|
||||
weight: 40
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
{{< feature-state state="stable" >}}
|
||||
|
||||
<!--
|
||||
This page shows how to assign extended resources to a Container.
|
||||
-->
|
||||
本文介绍如何为容器指定扩展资源。
|
||||
|
||||
{{< feature-state state="stable" >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
Before you do this exercise, do the exercise in
|
||||
[Advertise Extended Resources for a Node](/docs/tasks/administer-cluster/extended-resource-node/).
|
||||
That will configure one of your Nodes to advertise a dongle resource.
|
||||
-->
|
||||
在您开始此练习前,请先练习[为节点广播扩展资源](/docs/tasks/administer-cluster/extended-resource-node/)。
|
||||
在那个练习中将配置您的一个节点来广播 dongle 资源。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Assign an extended resource to a Pod
|
||||
|
||||
To request an extended resource, include the `resources:requests` field in your
|
||||
Container manifest. Extended resources are fully qualified with any domain outside of
|
||||
`*.kubernetes.io/`. Valid extended resource names have the form `example.com/foo` where
|
||||
`example.com` is replaced with your organization's domain and `foo` is a
|
||||
descriptive resource name.
|
||||
|
||||
Here is the configuration file for a Pod that has one Container:
|
||||
-->
|
||||
## 给 Pod 分派扩展资源
|
||||
|
||||
要请求扩展资源,需要在您的容器清单中包括 `resources:requests` 字段。
|
||||
扩展资源可以使用任何完全限定名称,只是不能使用 `*.kubernetes.io/`。
|
||||
有效的扩展资源名的格式为 `example.com/foo`,其中 `example.com` 应被替换为您的组织的域名,而 `foo` 则是描述性的资源名称。
|
||||
|
||||
下面是包含一个容器的 Pod 配置文件:
|
||||
|
||||
{{< codenew file="pods/resource/extended-resource-pod.yaml" >}}
|
||||
|
||||
<!--
|
||||
In the configuration file, you can see that the Container requests 3 dongles.
|
||||
|
||||
Create a Pod:
|
||||
-->
|
||||
在配置文件中,您可以看到容器请求了 3 个 dongles。
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
Verify that the Pod is running:
|
||||
-->
|
||||
检查 Pod 是否运行正常:
|
||||
|
||||
```shell
|
||||
kubectl get pod extended-resource-demo
|
||||
```
|
||||
|
||||
<!--
|
||||
Describe the Pod:
|
||||
-->
|
||||
描述 Pod:
|
||||
|
||||
```shell
|
||||
kubectl describe pod extended-resource-demo
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows dongle requests:
|
||||
-->
|
||||
输出结果显示 dongle 请求如下:
|
||||
|
||||
```yaml
|
||||
Limits:
|
||||
example.com/dongle: 3
|
||||
Requests:
|
||||
example.com/dongle: 3
|
||||
```
|
||||
|
||||
<!--
|
||||
## Attempt to create a second Pod
|
||||
|
||||
Here is the configuration file for a Pod that has one Container. The Container requests
|
||||
two dongles.
|
||||
-->
|
||||
## 尝试创建第二个 Pod
|
||||
|
||||
下面是包含一个容器的 Pod 配置文件,容器请求了 2 个 dongles。
|
||||
|
||||
{{< codenew file="pods/resource/extended-resource-pod-2.yaml" >}}
|
||||
|
||||
<!--
|
||||
Kubernetes will not be able to satisfy the request for two dongles, because the first Pod
|
||||
used three of the four available dongles.
|
||||
|
||||
Attempt to create a Pod:
|
||||
-->
|
||||
Kubernetes 将不能满足 2 个 dongles 的请求,因为第一个 Pod 已经使用了 4 个可用 dongles 中的 3 个。
|
||||
|
||||
尝试创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod-2.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
Describe the Pod
|
||||
-->
|
||||
描述 Pod
|
||||
|
||||
```shell
|
||||
kubectl describe pod extended-resource-demo-2
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that the Pod cannot be scheduled, because there is no Node that has
|
||||
2 dongles available:
|
||||
-->
|
||||
输出结果表明 Pod 不能被调度,因为没有一个节点上存在两个可用的 dongles。
|
||||
|
||||
```
|
||||
Conditions:
|
||||
Type Status
|
||||
PodScheduled False
|
||||
...
|
||||
Events:
|
||||
...
|
||||
... Warning FailedScheduling pod (extended-resource-demo-2) failed to fit in any node
|
||||
fit failure summary on nodes : Insufficient example.com/dongle (1)
|
||||
```
|
||||
|
||||
<!--
|
||||
View the Pod status:
|
||||
-->
|
||||
查看 Pod 的状态:
|
||||
|
||||
```shell
|
||||
kubectl get pod extended-resource-demo-2
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that the Pod was created, but not scheduled to run on a Node.
|
||||
It has a status of Pending:
|
||||
-->
|
||||
输出结果表明 Pod 虽然被创建了,但没有被调度到节点上正常运行。Pod 的状态为 Pending:
|
||||
|
||||
```yaml
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
extended-resource-demo-2 0/1 Pending 0 6m
|
||||
```
|
||||
|
||||
<!--
|
||||
## Clean up
|
||||
|
||||
Delete the Pods that you created for this exercise:
|
||||
-->
|
||||
## 环境清理
|
||||
|
||||
删除本练习中创建的 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod extended-resource-demo
|
||||
kubectl delete pod extended-resource-demo-2
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
### For application developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
-->
|
||||
## 应用开发者参考
|
||||
|
||||
* [为容器和 Pod 分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
* [为容器和 Pod 分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
<!--
|
||||
### For cluster administrators
|
||||
|
||||
* [Advertise Extended Resources for a Node](/docs/tasks/administer-cluster/extended-resource-node/)
|
||||
-->
|
||||
### 集群管理员参考
|
||||
|
||||
* [为节点广播扩展资源](/docs/tasks/administer-cluster/extended-resource-node/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
---
|
||||
title: 从私有仓库拉取镜像
|
||||
content_template: templates/task
|
||||
weight: 100
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: Pull an Image from a Private Registry
|
||||
content_template: templates/task
|
||||
weight: 100
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
This page shows how to create a Pod that uses a Secret to pull an image from a
|
||||
private Docker registry or repository.
|
||||
-->
|
||||
|
||||
本文介绍如何使用 Secret 从私有的 Docker 镜像仓库或代码仓库拉取镜像来创建 Pod。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
* {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
* To do this exercise, you need a
|
||||
[Docker ID](https://docs.docker.com/docker-id/) and password.
|
||||
-->
|
||||
|
||||
您需要 [Docker ID](https://docs.docker.com/docker-id/) 和密码来进行本练习。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Log in to Docker
|
||||
|
||||
On your laptop, you must authenticate with a registry in order to pull a private image:
|
||||
-->
|
||||
|
||||
## 登录 Docker 镜像仓库
|
||||
|
||||
在个人电脑上,要想拉取私有镜像必须在镜像仓库上进行身份验证。
|
||||
|
||||
```shell
|
||||
docker login
|
||||
```
|
||||
|
||||
<!--
|
||||
When prompted, enter your Docker username and password.
|
||||
|
||||
The login process creates or updates a `config.json` file that holds an authorization token.
|
||||
|
||||
View the `config.json` file:
|
||||
-->
|
||||
|
||||
当提示时,输入 Docker 用户名和密码。
|
||||
|
||||
登录过程会创建或更新保存有授权令牌的 `config.json` 文件。
|
||||
|
||||
查看 `config.json` 文件:
|
||||
|
||||
```shell
|
||||
cat ~/.docker/config.json
|
||||
```
|
||||
|
||||
<!--
|
||||
The output contains a section similar to this:
|
||||
-->
|
||||
|
||||
输出结果包含类似于以下内容的部分:
|
||||
|
||||
```json
|
||||
{
|
||||
"auths": {
|
||||
"https://index.docker.io/v1/": {
|
||||
"auth": "c3R...zE2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
If you use a Docker credentials store, you won't see that `auth` entry but a `credsStore` entry with the name of the store as value.
|
||||
-->
|
||||
如果使用 Docker 凭证仓库,则不会看到 `auth` 条目,看到的将是以仓库名称作为值的 `credsStore` 条目。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Create a Secret in the cluster that holds your authorization token
|
||||
|
||||
A Kubernetes cluster uses the Secret of `docker-registry` type to authenticate with a container registry to pull a private image.
|
||||
|
||||
Create this Secret, naming it `regcred`:
|
||||
-->
|
||||
|
||||
## 在集群中创建保存授权令牌的 Secret
|
||||
|
||||
Kubernetes 集群使用 `docker-registry` 类型的 Secret 来通过容器仓库的身份验证,进而提取私有映像。
|
||||
|
||||
创建 Secret,命名为 `regcred`:
|
||||
|
||||
```shell
|
||||
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
|
||||
```
|
||||
|
||||
<!--
|
||||
where:
|
||||
|
||||
* `<your-registry-server>` is your Private Docker Registry FQDN. (https://index.docker.io/v1/ for DockerHub)
|
||||
* `<your-name>` is your Docker username.
|
||||
* `<your-pword>` is your Docker password.
|
||||
* `<your-email>` is your Docker email.
|
||||
|
||||
You have successfully set your Docker credentials in the cluster as a Secret called `regcred`.
|
||||
-->
|
||||
|
||||
在这里:
|
||||
|
||||
* `<your-registry-server>` 是你的私有 Docker 仓库全限定域名(FQDN)。(参考 https://index.docker.io/v1/ 中关于 DockerHub 的部分)
|
||||
* `<your-name>` 是你的 Docker 用户名。
|
||||
* `<your-pword>` 是你的 Docker 密码。
|
||||
* `<your-email>` 是你的 Docker 邮箱。
|
||||
|
||||
这样您就成功地将集群中的 Docker 凭据设置为名为 `regcred` 的 Secret。
|
||||
|
||||
<!--
|
||||
## Inspecting the Secret `regcred`
|
||||
|
||||
To understand the contents of the `regcred` Secret you just created, start by viewing the Secret in YAML format:
|
||||
-->
|
||||
|
||||
## 检查 Secret `regcred`
|
||||
|
||||
要了解你创建的 `regcred` Secret 的内容,可以用 YAML 格式进行查看:
|
||||
|
||||
```shell
|
||||
kubectl get secret regcred --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The output is similar to this:
|
||||
-->
|
||||
|
||||
输出和下面类似:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
data:
|
||||
.dockerconfigjson: eyJodHRwczovL2luZGV4L ... J0QUl6RTIifX0=
|
||||
kind: Secret
|
||||
metadata:
|
||||
...
|
||||
name: regcred
|
||||
...
|
||||
type: kubernetes.io/dockerconfigjson
|
||||
```
|
||||
|
||||
<!--
|
||||
The value of the `.dockerconfigjson` field is a base64 representation of your Docker credentials.
|
||||
|
||||
To understand what is in the `.dockerconfigjson` field, convert the secret data to a
|
||||
readable format:
|
||||
-->
|
||||
|
||||
`.dockerconfigjson` 字段的值是 Docker 凭据的 base64 表示。
|
||||
|
||||
要了解 `dockerconfigjson` 字段中的内容,请将 Secret 数据转换为可读格式:
|
||||
|
||||
```shell
|
||||
kubectl get secret regcred --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode
|
||||
```
|
||||
|
||||
<!--
|
||||
The output is similar to this:
|
||||
-->
|
||||
|
||||
输出和下面类似:
|
||||
|
||||
```json
|
||||
{"auths":{"yourprivateregistry.com":{"username":"janedoe","password":"xxxxxxxxxxx","email":"jdoe@example.com","auth":"c3R...zE2"}}}
|
||||
```
|
||||
|
||||
<!--
|
||||
To understand what is in the `auth` field, convert the base64-encoded data to a readable format:
|
||||
-->
|
||||
|
||||
要了解 `auth` 字段中的内容,请将 base64 编码过的数据转换为可读格式:
|
||||
|
||||
```shell
|
||||
echo "c3R...zE2" | base64 --decode
|
||||
```
|
||||
|
||||
<!--
|
||||
The output, username and password concatenated with a `:`, is similar to this:
|
||||
-->
|
||||
|
||||
输出结果中,用户名和密码用 `:` 链接,类似下面这样:
|
||||
|
||||
```none
|
||||
janedoe:xxxxxxxxxxx
|
||||
```
|
||||
|
||||
<!--
|
||||
Notice that the Secret data contains the authorization token similar to your local `~/.docker/config.json` file.
|
||||
|
||||
You have successfully set your Docker credentials as a Secret called `regcred` in the cluster.
|
||||
|
||||
## Create a Pod that uses your Secret
|
||||
|
||||
Here is a configuration file for a Pod that needs access to your Docker credentials in `regcred`:
|
||||
-->
|
||||
|
||||
注意,Secret 数据包含与本地 `~/.docker/config.json` 文件类似的授权令牌。
|
||||
|
||||
这样您就已经成功地将 Docker 凭据设置为集群中的名为 `regcred` 的 Secret。
|
||||
|
||||
## 创建一个使用您的 Secret 的 Pod
|
||||
|
||||
下面是一个 Pod 配置文件,它需要访问 `regcred` 中的 Docker 凭据:
|
||||
|
||||
{{< codenew file="pods/private-reg-pod.yaml" >}}
|
||||
|
||||
<!--
|
||||
Download the above file:
|
||||
-->
|
||||
|
||||
下载上述文件:
|
||||
|
||||
```shell
|
||||
wget -O my-private-reg-pod.yaml https://k8s.io/examples/pods/private-reg-pod.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
In file `my-private-reg-pod.yaml`, replace `<your-private-image>` with the path to an image in a private registry such as:
|
||||
-->
|
||||
|
||||
在`my-private-reg-pod.yaml` 文件中,使用私有仓库的镜像路径替换 `<your-private-image>`,例如:
|
||||
|
||||
```none
|
||||
janedoe/jdoe-private:v1
|
||||
```
|
||||
|
||||
<!--
|
||||
To pull the image from the private registry, Kubernetes needs credentials.
|
||||
The `imagePullSecrets` field in the configuration file specifies that Kubernetes should get the credentials from a Secret named `regcred`.
|
||||
|
||||
Create a Pod that uses your Secret, and verify that the Pod is running:
|
||||
-->
|
||||
|
||||
要从私有仓库拉取镜像,Kubernetes 需要凭证。
|
||||
配置文件中的 `imagePullSecrets` 字段表明 Kubernetes 应该通过名为 `regcred` 的 Secret 获取凭证。
|
||||
|
||||
创建使用了你的 Secret 的 Pod,并检查它是否正常运行:
|
||||
|
||||
```shell
|
||||
kubectl create -f my-private-reg-pod.yaml
|
||||
kubectl get pod private-reg
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
<!--
|
||||
* Learn more about [Secrets](/docs/concepts/configuration/secret/).
|
||||
* Learn more about [using a private registry](/docs/concepts/containers/images/#using-a-private-registry).
|
||||
* See [kubectl create secret docker-registry](/docs/reference/generated/kubectl/kubectl-commands/#-em-secret-docker-registry-em-).
|
||||
* See [Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core).
|
||||
* See the `imagePullSecrets` field of [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core).
|
||||
-->
|
||||
|
||||
* 进一步了解 [Secrets](/docs/concepts/configuration/secret/)。
|
||||
* 进一步了解 [使用私有仓库](/docs/concepts/containers/images/#using-a-private-registry)。
|
||||
* 参考 [kubectl create secret docker-registry](/docs/reference/generated/kubectl/kubectl-commands/#-em-secret-docker-registry-em-)。
|
||||
* 参考 [Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)。
|
||||
* 参考 [PodSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core) 中的 `imagePullSecrets` 字段 。
|
||||
|
||||
{{% /capture %}}
|
||||
@@ -0,0 +1,443 @@
|
||||
---
|
||||
title: 配置 Pod 的服务质量
|
||||
content_template: templates/task
|
||||
weight: 30
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: Configure Quality of Service for Pods
|
||||
content_template: templates/task
|
||||
weight: 30
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
This page shows how to configure Pods so that they will be assigned particular
|
||||
Quality of Service (QoS) classes. Kubernetes uses QoS classes to make decisions about
|
||||
scheduling and evicting Pods.
|
||||
-->
|
||||
|
||||
本文介绍怎样配置 Pod 让其获得特定的服务质量(QoS)类。Kubernetes 使用 QoS 类来决定 Pod 的调度和驱逐策略。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## QoS classes
|
||||
|
||||
When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:
|
||||
-->
|
||||
|
||||
## QoS 类
|
||||
|
||||
Kubernetes 创建 Pod 时就给它指定了下列一种 QoS 类:
|
||||
|
||||
* Guaranteed
|
||||
* Burstable
|
||||
* BestEffort
|
||||
|
||||
<!--
|
||||
## Create a namespace
|
||||
|
||||
Create a namespace so that the resources you create in this exercise are
|
||||
isolated from the rest of your cluster.
|
||||
-->
|
||||
|
||||
## 创建命名空间
|
||||
|
||||
创建一个命名空间,以便将本练习所创建的资源与集群的其余资源相隔离。
|
||||
|
||||
```shell
|
||||
kubectl create namespace qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Create a Pod that gets assigned a QoS class of Guaranteed
|
||||
|
||||
For a Pod to be given a QoS class of Guaranteed:
|
||||
|
||||
* Every Container in the Pod must have a memory limit and a memory request, and they must be the same.
|
||||
* Every Container in the Pod must have a CPU limit and a CPU request, and they must be the same.
|
||||
|
||||
Here is the configuration file for a Pod that has one Container. The Container has a memory limit and a
|
||||
memory request, both equal to 200 MiB. The Container has a CPU limit and a CPU request, both equal to 700 milliCPU:
|
||||
-->
|
||||
|
||||
## 创建一个 QoS 类为 Guaranteed 的 Pod
|
||||
|
||||
对于 QoS 类为 Guaranteed 的 Pod:
|
||||
|
||||
* Pod 中的每个容器必须指定内存请求和内存限制,并且两者要相等。
|
||||
* Pod 中的每个容器必须指定 CPU 请求和 CPU 限制,并且两者要相等。
|
||||
|
||||
下面是包含一个容器的 Pod 配置文件。
|
||||
容器设置了内存请求和内存限制,值都是 200 MiB。
|
||||
容器设置了 CPU 请求和 CPU 限制,值都是 700 milliCPU:
|
||||
|
||||
{{< codenew file="pods/qos/qos-pod.yaml" >}}
|
||||
|
||||
<!--
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/qos/qos-pod.yaml --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod:
|
||||
-->
|
||||
|
||||
查看 Pod 详情:
|
||||
|
||||
```shell
|
||||
kubectl get pod qos-demo --namespace=qos-example --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that Kubernetes gave the Pod a QoS class of Guaranteed. The output also
|
||||
verifies that the Pod Container has a memory request that matches its memory limit, and it has
|
||||
a CPU request that matches its CPU limit.
|
||||
-->
|
||||
|
||||
结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Guaranteed。
|
||||
结果也确认了 Pod 容器设置了与内存限制匹配的内存请求,设置了与 CPU 限制匹配的 CPU 请求。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
containers:
|
||||
...
|
||||
resources:
|
||||
limits:
|
||||
cpu: 700m
|
||||
memory: 200Mi
|
||||
requests:
|
||||
cpu: 700m
|
||||
memory: 200Mi
|
||||
...
|
||||
qosClass: Guaranteed
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
If a Container specifies its own memory limit, but does not specify a memory request, Kubernetes
|
||||
automatically assigns a memory request that matches the limit. Similarly, if a Container specifies its own
|
||||
CPU limit, but does not specify a CPU request, Kubernetes automatically assigns a CPU request that matches
|
||||
the limit.
|
||||
-->
|
||||
|
||||
如果容器指定了自己的内存限制,但没有指定内存请求,Kubernetes 会自动为它指定与内存限制匹配的内存请求。
|
||||
同样,如果容器指定了自己的 CPU 限制,但没有指定 CPU 请求,Kubernetes 会自动为它指定与 CPU 限制匹配的 CPU 请求。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
删除 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod qos-demo --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Create a Pod that gets assigned a QoS class of Burstable
|
||||
|
||||
A Pod is given a QoS class of Burstable if:
|
||||
|
||||
* The Pod does not meet the criteria for QoS class Guaranteed.
|
||||
* At least one Container in the Pod has a memory or CPU request.
|
||||
|
||||
Here is the configuration file for a Pod that has one Container. The Container has a memory limit of 200 MiB
|
||||
and a memory request of 100 MiB.
|
||||
-->
|
||||
|
||||
## 创建一个 QoS 类为 Burstable 的 Pod
|
||||
|
||||
如果满足下面条件,将会指定 Pod 的 QoS 类为 Burstable:
|
||||
|
||||
* Pod 不符合 Guaranteed QoS 类的标准。
|
||||
* Pod 中至少一个容器具有内存或 CPU 请求。
|
||||
|
||||
下面是包含一个容器的 Pod 配置文件。
|
||||
容器设置了内存限制 200 MiB 和内存请求 100 MiB。
|
||||
|
||||
{{< codenew file="pods/qos/qos-pod-2.yaml" >}}
|
||||
|
||||
<!--
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/qos/qos-pod-2.yaml --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod:
|
||||
-->
|
||||
|
||||
查看 Pod 详情:
|
||||
|
||||
```shell
|
||||
kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that Kubernetes gave the Pod a QoS class of Burstable.
|
||||
-->
|
||||
|
||||
结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
imagePullPolicy: Always
|
||||
name: qos-demo-2-ctr
|
||||
resources:
|
||||
limits:
|
||||
memory: 200Mi
|
||||
requests:
|
||||
memory: 100Mi
|
||||
...
|
||||
qosClass: Burstable
|
||||
```
|
||||
|
||||
<!--
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
删除 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod qos-demo-2 --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Create a Pod that gets assigned a QoS class of BestEffort
|
||||
|
||||
For a Pod to be given a QoS class of BestEffort, the Containers in the Pod must not
|
||||
have any memory or CPU limits or requests.
|
||||
|
||||
Here is the configuration file for a Pod that has one Container. The Container has no memory or CPU
|
||||
limits or requests:
|
||||
-->
|
||||
|
||||
## 创建一个 QoS 类为 BestEffort 的 Pod
|
||||
|
||||
对于 QoS 类为 BestEffort 的 Pod,Pod 中的容器必须没有设置内存和 CPU 限制或请求。
|
||||
|
||||
下面是包含一个容器的 Pod 配置文件。
|
||||
容器没有设置内存和 CPU 限制或请求。
|
||||
|
||||
|
||||
|
||||
{{< codenew file="pods/qos/qos-pod-3.yaml" >}}
|
||||
|
||||
<!--
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/qos/qos-pod-3.yaml --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod:
|
||||
-->
|
||||
|
||||
查看 Pod 详情:
|
||||
|
||||
```shell
|
||||
kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that Kubernetes gave the Pod a QoS class of BestEffort.
|
||||
-->
|
||||
|
||||
结果表明 Kubernetes 为 Pod 配置的 QoS 类为 BestEffort。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
containers:
|
||||
...
|
||||
resources: {}
|
||||
...
|
||||
qosClass: BestEffort
|
||||
```
|
||||
|
||||
<!--
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
删除 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod qos-demo-3 --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Create a Pod that has two Containers
|
||||
|
||||
Here is the configuration file for a Pod that has two Containers. One container specifies a memory
|
||||
request of 200 MiB. The other Container does not specify any requests or limits.
|
||||
-->
|
||||
|
||||
## 创建包含两个容器的 Pod
|
||||
|
||||
下面是包含两个容器的 Pod 配置文件。
|
||||
一个容器指定了内存请求 200 MiB。
|
||||
另外一个容器没有指定任何请求和限制。
|
||||
|
||||
|
||||
{{< codenew file="pods/qos/qos-pod-4.yaml" >}}
|
||||
|
||||
<!--
|
||||
Notice that this Pod meets the criteria for QoS class Burstable. That is, it does not meet the
|
||||
criteria for QoS class Guaranteed, and one of its Containers has a memory request.
|
||||
|
||||
Create the Pod:
|
||||
-->
|
||||
|
||||
注意此 Pod 满足 Burstable QoS 类的标准。
|
||||
也就是说它不满足 Guaranteed QoS 类标准,因为它的一个容器设有内存请求。
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/pods/qos/qos-pod-4.yaml --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
View detailed information about the Pod:
|
||||
-->
|
||||
|
||||
查看 Pod 详情:
|
||||
|
||||
```shell
|
||||
kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shows that Kubernetes gave the Pod a QoS class of Burstable:
|
||||
-->
|
||||
|
||||
结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
containers:
|
||||
...
|
||||
name: qos-demo-4-ctr-1
|
||||
resources:
|
||||
requests:
|
||||
memory: 200Mi
|
||||
...
|
||||
name: qos-demo-4-ctr-2
|
||||
resources: {}
|
||||
...
|
||||
qosClass: Burstable
|
||||
```
|
||||
|
||||
<!--
|
||||
Delete your Pod:
|
||||
-->
|
||||
|
||||
删除 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod qos-demo-4 --namespace=qos-example
|
||||
```
|
||||
|
||||
<!--
|
||||
## Clean up
|
||||
|
||||
Delete your namespace:
|
||||
-->
|
||||
|
||||
## 环境清理
|
||||
|
||||
删除命名空间:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace qos-example
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
|
||||
<!--
|
||||
### For app developers
|
||||
|
||||
* [Assign Memory Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
-->
|
||||
|
||||
### 应用开发者参考
|
||||
|
||||
* [为 Pod 和容器分配内存资源](/docs/tasks/configure-pod-container/assign-memory-resource/)
|
||||
|
||||
* [为 Pod 和容器分配 CPU 资源](/docs/tasks/configure-pod-container/assign-cpu-resource/)
|
||||
|
||||
<!--
|
||||
### For cluster administrators
|
||||
|
||||
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
* [Control Topology Management policies on a node](/docs/tasks/administer-cluster/topology-manager/)
|
||||
-->
|
||||
|
||||
### 集群管理员参考
|
||||
|
||||
* [为命名空间配置默认的内存请求和限制](/docs/tasks/administer-cluster/memory-default-namespace/)
|
||||
|
||||
* [为命名空间配置默认的 CPU 请求和限制](/docs/tasks/administer-cluster/cpu-default-namespace/)
|
||||
|
||||
* [为命名空间配置最小和最大内存限制](/docs/tasks/administer-cluster/memory-constraint-namespace/)
|
||||
|
||||
* [为命名空间配置最小和最大 CPU 限制](/docs/tasks/administer-cluster/cpu-constraint-namespace/)
|
||||
|
||||
* [为命名空间配置内存和 CPU 配额](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/)
|
||||
|
||||
* [为命名空间配置 Pod 配额](/docs/tasks/administer-cluster/quota-pod-namespace/)
|
||||
|
||||
* [为 API 对象配置配额](/docs/tasks/administer-cluster/quota-api-object/)
|
||||
|
||||
* [控制节点上的拓扑管理策略](/docs/tasks/administer-cluster/topology-manager/)
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
---
|
||||
title: 在 Pod 中的容器之间共享进程命名空间
|
||||
min-kubernetes-server-version: v1.10
|
||||
content_template: templates/task
|
||||
weight: 160
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: Share Process Namespace between Containers in a Pod
|
||||
min-kubernetes-server-version: v1.10
|
||||
reviewers:
|
||||
- verb
|
||||
- yujuhong
|
||||
- dchen1107
|
||||
content_template: templates/task
|
||||
weight: 160
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
{{< feature-state state="beta" >}}
|
||||
|
||||
<!--
|
||||
This page shows how to configure process namespace sharing for a pod. When
|
||||
process namespace sharing is enabled, processes in a container are visible
|
||||
to all other containers in that pod.
|
||||
-->
|
||||
此页面展示如何为 pod 配置进程命名空间共享。
|
||||
当启用进程命名空间共享时,容器中的进程对该 pod 中的所有其他容器都是可见的。
|
||||
|
||||
<!--
|
||||
You can use this feature to configure cooperating containers, such as a log
|
||||
handler sidecar container, or to troubleshoot container images that don't
|
||||
include debugging utilities like a shell.
|
||||
-->
|
||||
您可以使用此功能来配置协作容器,比如日志处理 sidecar 容器,或者对那些不包含诸如 shell 等调试实用工具的镜像进行故障排查。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
Process Namespace Sharing is a **beta** feature that is enabled by default. It
|
||||
may be disabled by setting `--feature-gates=PodShareProcessNamespace=false`.
|
||||
-->
|
||||
进程命名空间共享是默认启用的 **beta** 版功能。
|
||||
您可以通过设置 `--feature-gates=PodShareProcessNamespace=false` 禁用此功能。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Configure a Pod
|
||||
-->
|
||||
## 配置 Pod
|
||||
|
||||
<!--
|
||||
Process Namespace Sharing is enabled using the `ShareProcessNamespace` field of
|
||||
`v1.PodSpec`. For example:
|
||||
-->
|
||||
进程命名空间共享使用 `v1.PodSpec` 中的 `ShareProcessNamespace` 字段启用。例如:
|
||||
|
||||
{{< codenew file="pods/share-process-namespace.yaml" >}}
|
||||
|
||||
<!--
|
||||
1. Create the pod `nginx` on your cluster:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
|
||||
```
|
||||
|
||||
1. Attach to the `shell` container and run `ps`:
|
||||
|
||||
```shell
|
||||
kubectl attach -it nginx -c shell
|
||||
```
|
||||
|
||||
If you don't see a command prompt, try pressing enter.
|
||||
|
||||
```
|
||||
/ # ps ax
|
||||
PID USER TIME COMMAND
|
||||
1 root 0:00 /pause
|
||||
8 root 0:00 nginx: master process nginx -g daemon off;
|
||||
14 101 0:00 nginx: worker process
|
||||
15 root 0:00 sh
|
||||
21 root 0:00 ps ax
|
||||
```
|
||||
-->
|
||||
1. 在集群中创建 `nginx` pod:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/share-process-namespace.yaml
|
||||
```
|
||||
1. 获取容器 `shell`,执行 `ps`:
|
||||
|
||||
```shell
|
||||
kubectl attach -it nginx -c shell
|
||||
```
|
||||
如果没有看到命令提示符,请按 enter 回车键。
|
||||
|
||||
```
|
||||
/ # ps ax
|
||||
PID USER TIME COMMAND
|
||||
1 root 0:00 /pause
|
||||
8 root 0:00 nginx: master process nginx -g daemon off;
|
||||
14 101 0:00 nginx: worker process
|
||||
15 root 0:00 sh
|
||||
21 root 0:00 ps ax
|
||||
```
|
||||
<!--
|
||||
You can signal processes in other containers. For example, send `SIGHUP` to
|
||||
nginx to restart the worker process. This requires the `SYS_PTRACE` capability.
|
||||
-->
|
||||
您可以在其他容器中对进程发出信号。例如,发送 `SIGHUP` 到 nginx 以重启工作进程。这需要 `SYS_PTRACE` 功能。
|
||||
|
||||
```
|
||||
/ # kill -HUP 8
|
||||
/ # ps ax
|
||||
PID USER TIME COMMAND
|
||||
1 root 0:00 /pause
|
||||
8 root 0:00 nginx: master process nginx -g daemon off;
|
||||
15 root 0:00 sh
|
||||
22 101 0:00 nginx: worker process
|
||||
23 root 0:00 ps ax
|
||||
```
|
||||
|
||||
<!--
|
||||
It's even possible to access another container image using the
|
||||
`/proc/$pid/root` link.
|
||||
-->
|
||||
甚至可以使用 `/proc/$pid/root` 链接访问另一个容器镜像。
|
||||
|
||||
```
|
||||
/ # head /proc/8/root/etc/nginx/nginx.conf
|
||||
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture discussion %}}
|
||||
|
||||
<!--
|
||||
## Understanding Process Namespace Sharing
|
||||
-->
|
||||
## 理解进程命名空间共享
|
||||
|
||||
<!--
|
||||
Pods share many resources so it makes sense they would also share a process
|
||||
namespace. Some container images may expect to be isolated from other
|
||||
containers, though, so it's important to understand these differences:
|
||||
-->
|
||||
Pod 共享许多资源,因此它们共享进程命名空间是很有意义的。
|
||||
不过,有些容器镜像可能希望与其他容器隔离,因此了解这些差异很重要:
|
||||
|
||||
<!--
|
||||
1. **The container process no longer has PID 1.** Some container images refuse
|
||||
to start without PID 1 (for example, containers using `systemd`) or run
|
||||
commands like `kill -HUP 1` to signal the container process. In pods with a
|
||||
shared process namespace, `kill -HUP 1` will signal the pod sandbox.
|
||||
(`/pause` in the above example.)
|
||||
|
||||
1. **Processes are visible to other containers in the pod.** This includes all
|
||||
information visible in `/proc`, such as passwords that were passed as arguments
|
||||
or environment variables. These are protected only by regular Unix permissions.
|
||||
|
||||
1. **Container filesystems are visible to other containers in the pod through the
|
||||
`/proc/$pid/root` link.** This makes debugging easier, but it also means
|
||||
that filesystem secrets are protected only by filesystem permissions.
|
||||
-->
|
||||
|
||||
1. **容器进程不再具有 PID 1。** 在没有 PID 1 的情况下,一些容器镜像拒绝启动(例如,使用 `systemd` 的容器),或者拒绝执行 `kill -HUP 1` 之类的命令来通知容器进程。在具有共享进程命名空间的 pod 中,`kill -HUP 1` 将通知 pod 沙箱(在上面的例子中是 `/pause`)。
|
||||
|
||||
2. **进程对 pod 中的其他容器可见。** 这包括 `/proc` 中可见的所有信息,例如作为参数或环境变量传递的密码。这些仅受常规 Unix 权限的保护。
|
||||
|
||||
3. **容器文件系统通过 `/proc/$pid/root` 链接对 pod 中的其他容器可见。** 这使调试更加容易,但也意味着文件系统安全性只受文件系统权限的保护。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
@@ -0,0 +1,844 @@
|
||||
---
|
||||
reviewers:
|
||||
- cdrage
|
||||
title: 将 Docker Compose 文件转换为 Kubernetes 资源
|
||||
content_template: templates/task
|
||||
weight: 200
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
reviewers:
|
||||
- cdrage
|
||||
title: Translate a Docker Compose File to Kubernetes Resources
|
||||
content_template: templates/task
|
||||
weight: 170
|
||||
---
|
||||
-->
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
<!--
|
||||
What's Kompose? It's a conversion tool for all things compose (namely Docker Compose) to container orchestrators (Kubernetes or OpenShift).
|
||||
-->
|
||||
|
||||
Kompose 是什么?它是个转换工具,可将 compose(即 Docker Compose)所组装的所有内容转换成容器编排器(Kubernetes 或 OpenShift)可识别的形式。
|
||||
|
||||
<!--
|
||||
More information can be found on the Kompose website at [http://kompose.io](http://kompose.io).
|
||||
-->
|
||||
|
||||
更多信息请参考 Kompose 官网 [http://kompose.io](http://kompose.io)。
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
<!--
|
||||
## Install Kompose
|
||||
-->
|
||||
|
||||
## 安装 Kompose
|
||||
|
||||
<!--
|
||||
We have multiple ways to install Kompose. Our preferred method is downloading the binary from the latest GitHub release.
|
||||
-->
|
||||
|
||||
我们有很多种方式安装 Kompose。首选方式是从最新的 GitHub 发布页面下载二进制文件。
|
||||
|
||||
<!--
|
||||
## GitHub release
|
||||
-->
|
||||
|
||||
## GitHub 发布版本
|
||||
|
||||
<!--
|
||||
Kompose is released via GitHub on a three-week cycle, you can see all current releases on the [GitHub release page](https://github.com/kubernetes/kompose/releases).
|
||||
-->
|
||||
|
||||
Kompose 通过 GitHub 发布版本,发布周期为三星期。您可以在[GitHub 发布页面](https://github.com/kubernetes/kompose/releases)上看到所有当前版本。
|
||||
|
||||
```sh
|
||||
# Linux
|
||||
curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-linux-amd64 -o kompose
|
||||
|
||||
# macOS
|
||||
curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-darwin-amd64 -o kompose
|
||||
|
||||
# Windows
|
||||
curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-windows-amd64.exe -o kompose.exe
|
||||
|
||||
chmod +x kompose
|
||||
sudo mv ./kompose /usr/local/bin/kompose
|
||||
```
|
||||
|
||||
<!--
|
||||
Alternatively, you can download the [tarball](https://github.com/kubernetes/kompose/releases).
|
||||
-->
|
||||
或者,您可以下载 [tarball](https://github.com/kubernetes/kompose/releases)。
|
||||
|
||||
## Go
|
||||
|
||||
<!--
|
||||
Installing using `go get` pulls from the master branch with the latest development changes.
|
||||
-->
|
||||
|
||||
用 `go get` 命令从主分支拉取最新的开发变更的方法安装 Kompose。
|
||||
|
||||
|
||||
```sh
|
||||
go get -u github.com/kubernetes/kompose
|
||||
```
|
||||
|
||||
## CentOS
|
||||
|
||||
<!--
|
||||
Kompose is in [EPEL](https://fedoraproject.org/wiki/EPEL) CentOS repository.
|
||||
If you don't have [EPEL](https://fedoraproject.org/wiki/EPEL) repository already installed and enabled you can do it by running `sudo yum install epel-release`
|
||||
-->
|
||||
|
||||
Kompose 位于 [EPEL](https://fedoraproject.org/wiki/EPEL) CentOS 代码仓库。
|
||||
如果您还没有安装启用 [EPEL](https://fedoraproject.org/wiki/EPEL) 代码仓库,请运行命令 `sudo yum install epel-release`。
|
||||
|
||||
<!--
|
||||
If you have [EPEL](https://fedoraproject.org/wiki/EPEL) enabled in your system, you can install Kompose like any other package.
|
||||
-->
|
||||
|
||||
如果您的系统中已经启用了 [EPEL](https://fedoraproject.org/wiki/EPEL),您就可以像安装其他软件包一样安装 Kompose。
|
||||
|
||||
```bash
|
||||
sudo yum -y install kompose
|
||||
```
|
||||
|
||||
## Fedora
|
||||
|
||||
<!--
|
||||
Kompose is in Fedora 24, 25 and 26 repositories. You can install it just like any other package.
|
||||
-->
|
||||
|
||||
Kompose 位于 Fedora 24、25 和 26 的代码仓库。您可以像安装其他软件包一样安装 Kompose。
|
||||
|
||||
```bash
|
||||
sudo dnf -y install kompose
|
||||
```
|
||||
|
||||
## macOS
|
||||
|
||||
<!--
|
||||
On macOS you can install latest release via [Homebrew](https://brew.sh):
|
||||
-->
|
||||
|
||||
在 macOS 上您可以通过 [Homebrew](https://brew.sh) 安装 Kompose 的最新版本:
|
||||
|
||||
```bash
|
||||
brew install kompose
|
||||
|
||||
```
|
||||
<!--
|
||||
## Use Kompose
|
||||
-->
|
||||
|
||||
## 使用 Kompose
|
||||
|
||||
<!--
|
||||
In just a few steps, we'll take you from Docker Compose to Kubernetes. All
|
||||
you need is an existing `docker-compose.yml` file.
|
||||
-->
|
||||
|
||||
再需几步,我们就把你从 Docker Compose 带到 Kubernetes。
|
||||
您只需要一个现有的 `docker-compose.yml` 文件。
|
||||
|
||||
1. <!--Go to the directory containing your `docker-compose.yml` file. If you don't
|
||||
have one, test using this one.-->
|
||||
进入 `docker-compose.yml` 文件所在的目录。如果没有,请使用下面这个进行测试。
|
||||
|
||||
```yaml
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
|
||||
redis-master:
|
||||
image: k8s.gcr.io/redis:e2e
|
||||
ports:
|
||||
- "6379"
|
||||
|
||||
redis-slave:
|
||||
image: gcr.io/google_samples/gb-redisslave:v3
|
||||
ports:
|
||||
- "6379"
|
||||
environment:
|
||||
- GET_HOSTS_FROM=dns
|
||||
|
||||
frontend:
|
||||
image: gcr.io/google-samples/gb-frontend:v4
|
||||
ports:
|
||||
- "80:80"
|
||||
environment:
|
||||
- GET_HOSTS_FROM=dns
|
||||
labels:
|
||||
kompose.service.type: LoadBalancer
|
||||
```
|
||||
|
||||
|
||||
2. <!--Run the `kompose up` command to deploy to Kubernetes directly, or skip to
|
||||
the next step instead to generate a file to use with `kubectl`.-->
|
||||
运行 `kompose up` 命令直接部署到 Kubernetes,或者跳到下一步,生成 `kubectl` 使用的文件。
|
||||
|
||||
```bash
|
||||
$ kompose up
|
||||
We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application.
|
||||
If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
|
||||
|
||||
INFO Successfully created Service: redis
|
||||
INFO Successfully created Service: web
|
||||
INFO Successfully created Deployment: redis
|
||||
INFO Successfully created Deployment: web
|
||||
|
||||
Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.
|
||||
```
|
||||
|
||||
|
||||
3. <!--To convert the `docker-compose.yml` file to files that you can use with
|
||||
`kubectl`, run `kompose convert` and then `kubectl create -f <output file>`.-->
|
||||
要将 `docker-compose.yml` 转换为 `kubectl` 可用的文件,请运行 `kompose convert` 命令进行转换,然后运行 `kubectl create -f <output file>` 进行创建。
|
||||
|
||||
```bash
|
||||
$ kompose convert
|
||||
INFO Kubernetes file "frontend-service.yaml" created
|
||||
INFO Kubernetes file "redis-master-service.yaml" created
|
||||
INFO Kubernetes file "redis-slave-service.yaml" created
|
||||
INFO Kubernetes file "frontend-deployment.yaml" created
|
||||
INFO Kubernetes file "redis-master-deployment.yaml" created
|
||||
INFO Kubernetes file "redis-slave-deployment.yaml" created
|
||||
```
|
||||
|
||||
```bash
|
||||
$ kubectl create -f frontend-service.yaml,redis-master-service.yaml,redis-slave-service.yaml,frontend-deployment.yaml,redis-master-deployment.yaml,redis-slave-deployment.yaml
|
||||
service/frontend created
|
||||
service/redis-master created
|
||||
service/redis-slave created
|
||||
deployment.apps/frontend created
|
||||
deployment.apps/redis-master created
|
||||
deployment.apps/redis-slave created
|
||||
```
|
||||
<!--
|
||||
Your deployments are running in Kubernetes.
|
||||
-->
|
||||
您部署的应用在 Kubernetes 中运行起来了。
|
||||
|
||||
|
||||
4. <!--Access your application.-->访问您的应用。
|
||||
|
||||
<!--If you're already using `minikube` for your development process:-->
|
||||
|
||||
如果您在开发过程中使用 `minikube`,请执行:
|
||||
|
||||
```bash
|
||||
$ minikube service frontend
|
||||
```
|
||||
|
||||
<!--Otherwise, let's look up what IP your service is using!-->
|
||||
否则,我们要查看一下您的服务使用了什么 IP!
|
||||
|
||||
```sh
|
||||
$ kubectl describe svc frontend
|
||||
Name: frontend
|
||||
Namespace: default
|
||||
Labels: service=frontend
|
||||
Selector: service=frontend
|
||||
Type: LoadBalancer
|
||||
IP: 10.0.0.183
|
||||
LoadBalancer Ingress: 192.0.2.89
|
||||
Port: 80 80/TCP
|
||||
NodePort: 80 31144/TCP
|
||||
Endpoints: 172.17.0.4:80
|
||||
Session Affinity: None
|
||||
No events.
|
||||
|
||||
```
|
||||
|
||||
<!--If you're using a cloud provider, your IP will be listed next to `LoadBalancer Ingress`.-->
|
||||
如果您使用的是云提供商,您的 IP 将在 `LoadBalancer Ingress` 字段给出。
|
||||
|
||||
```sh
|
||||
$ curl http://192.0.2.89
|
||||
```
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture discussion %}}
|
||||
|
||||
<!--
|
||||
## User Guide
|
||||
-->
|
||||
|
||||
## 用户指南
|
||||
|
||||
<!--
|
||||
- CLI
|
||||
- [`kompose convert`](#kompose-convert)
|
||||
- [`kompose up`](#kompose-up)
|
||||
- [`kompose down`](#kompose-down)
|
||||
- Documentation
|
||||
- [Build and Push Docker Images](#build-and-push-docker-images)
|
||||
- [Alternative Conversions](#alternative-conversions)
|
||||
- [Labels](#labels)
|
||||
- [Restart](#restart)
|
||||
- [Docker Compose Versions](#docker-compose-versions)
|
||||
-->
|
||||
|
||||
- CLI
|
||||
- [`kompose convert`](#kompose-convert)
|
||||
- [`kompose up`](#kompose-up)
|
||||
- [`kompose down`](#kompose-down)
|
||||
- 文档
|
||||
- [构建和推送 Docker 镜像](#构建和推送-docker-镜像)
|
||||
- [其他转换方式](#其他转换方式)
|
||||
- [标签](#标签)
|
||||
- [重启](#重启)
|
||||
- [Docker Compose 版本](#docker-compose-版本)
|
||||
|
||||
<!--
|
||||
Kompose has support for two providers: OpenShift and Kubernetes.
|
||||
You can choose a targeted provider using global option `--provider`. If no provider is specified, Kubernetes is set by default.
|
||||
-->
|
||||
|
||||
Kompose 支持两种驱动:OpenShift 和 Kubernetes。
|
||||
您可以通过全局选项 `--provider` 选择驱动方式。如果没有指定,会将 Kubernetes 作为默认驱动。
|
||||
|
||||
## `kompose convert`
|
||||
|
||||
Kompose 支持将 V1、V2 和 V3 版本的 Docker Compose 文件转换为 Kubernetes 和 OpenShift 资源对象。
|
||||
|
||||
### Kubernetes
|
||||
|
||||
```sh
|
||||
$ kompose --file docker-voting.yml convert
|
||||
WARN Unsupported key networks - ignoring
|
||||
WARN Unsupported key build - ignoring
|
||||
INFO Kubernetes file "worker-svc.yaml" created
|
||||
INFO Kubernetes file "db-svc.yaml" created
|
||||
INFO Kubernetes file "redis-svc.yaml" created
|
||||
INFO Kubernetes file "result-svc.yaml" created
|
||||
INFO Kubernetes file "vote-svc.yaml" created
|
||||
INFO Kubernetes file "redis-deployment.yaml" created
|
||||
INFO Kubernetes file "result-deployment.yaml" created
|
||||
INFO Kubernetes file "vote-deployment.yaml" created
|
||||
INFO Kubernetes file "worker-deployment.yaml" created
|
||||
INFO Kubernetes file "db-deployment.yaml" created
|
||||
|
||||
$ ls
|
||||
db-deployment.yaml docker-compose.yml docker-gitlab.yml redis-deployment.yaml result-deployment.yaml vote-deployment.yaml worker-deployment.yaml
|
||||
db-svc.yaml docker-voting.yml redis-svc.yaml result-svc.yaml vote-svc.yaml worker-svc.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
You can also provide multiple docker-compose files at the same time:
|
||||
-->
|
||||
|
||||
您也可以同时提供多个 docker-compose 文件进行转换:
|
||||
|
||||
```sh
|
||||
$ kompose -f docker-compose.yml -f docker-guestbook.yml convert
|
||||
INFO Kubernetes file "frontend-service.yaml" created
|
||||
INFO Kubernetes file "mlbparks-service.yaml" created
|
||||
INFO Kubernetes file "mongodb-service.yaml" created
|
||||
INFO Kubernetes file "redis-master-service.yaml" created
|
||||
INFO Kubernetes file "redis-slave-service.yaml" created
|
||||
INFO Kubernetes file "frontend-deployment.yaml" created
|
||||
INFO Kubernetes file "mlbparks-deployment.yaml" created
|
||||
INFO Kubernetes file "mongodb-deployment.yaml" created
|
||||
INFO Kubernetes file "mongodb-claim0-persistentvolumeclaim.yaml" created
|
||||
INFO Kubernetes file "redis-master-deployment.yaml" created
|
||||
INFO Kubernetes file "redis-slave-deployment.yaml" created
|
||||
|
||||
$ ls
|
||||
mlbparks-deployment.yaml mongodb-service.yaml redis-slave-service.jsonmlbparks-service.yaml
|
||||
frontend-deployment.yaml mongodb-claim0-persistentvolumeclaim.yaml redis-master-service.yaml
|
||||
frontend-service.yaml mongodb-deployment.yaml redis-slave-deployment.yaml
|
||||
redis-master-deployment.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
When multiple docker-compose files are provided the configuration is merged. Any configuration that is common will be over ridden by subsequent file.
|
||||
-->
|
||||
|
||||
当提供多个 docker-compose 文件时,配置将会合并。任何通用的配置都将被后续文件覆盖。
|
||||
|
||||
### OpenShift
|
||||
|
||||
```sh
|
||||
$ kompose --provider openshift --file docker-voting.yml convert
|
||||
WARN [worker] Service cannot be created because of missing port.
|
||||
INFO OpenShift file "vote-service.yaml" created
|
||||
INFO OpenShift file "db-service.yaml" created
|
||||
INFO OpenShift file "redis-service.yaml" created
|
||||
INFO OpenShift file "result-service.yaml" created
|
||||
INFO OpenShift file "vote-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "vote-imagestream.yaml" created
|
||||
INFO OpenShift file "worker-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "worker-imagestream.yaml" created
|
||||
INFO OpenShift file "db-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "db-imagestream.yaml" created
|
||||
INFO OpenShift file "redis-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "redis-imagestream.yaml" created
|
||||
INFO OpenShift file "result-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "result-imagestream.yaml" created
|
||||
```
|
||||
|
||||
<!--
|
||||
It also supports creating buildconfig for build directive in a service. By default, it uses the remote repo for the current git branch as the source repo, and the current branch as the source branch for the build. You can specify a different source repo and branch using ``--build-repo`` and ``--build-branch`` options respectively.
|
||||
-->
|
||||
|
||||
kompose 还支持为服务中的构建指令创建 buildconfig。
|
||||
默认情况下,它使用当前 git 分支的 remote 仓库作为源仓库,使用当前分支作为构建的源分支。
|
||||
您可以分别使用 ``--build-repo`` 和 ``--build-branch`` 选项指定不同的源仓库和分支。
|
||||
|
||||
```sh
|
||||
$ kompose --provider openshift --file buildconfig/docker-compose.yml convert
|
||||
WARN [foo] Service cannot be created because of missing port.
|
||||
INFO OpenShift Buildconfig using git@github.com:rtnpro/kompose.git::master as source.
|
||||
INFO OpenShift file "foo-deploymentconfig.yaml" created
|
||||
INFO OpenShift file "foo-imagestream.yaml" created
|
||||
INFO OpenShift file "foo-buildconfig.yaml" created
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
If you are manually pushing the Openshift artifacts using ``oc create -f``, you need to ensure that you push the imagestream artifact before the buildconfig artifact, to workaround this Openshift issue: https://github.com/openshift/origin/issues/4518 .
|
||||
-->
|
||||
|
||||
如果使用 ``oc create -f`` 手动推送 Openshift 工件,则需要确保在构建配置工件之前推送 imagestream 工件,以解决 Openshift 的这个问题:https://github.com/openshift/origin/issues/4518 。
|
||||
{{< /note >}}
|
||||
|
||||
## `kompose up`
|
||||
|
||||
<!--
|
||||
Kompose supports a straightforward way to deploy your "composed" application to Kubernetes or OpenShift via `kompose up`.
|
||||
-->
|
||||
|
||||
Kompose 支持通过 `kompose up` 直接将您的"复合的(composed)" 应用程序部署到 Kubernetes 或 OpenShift。
|
||||
|
||||
### Kubernetes
|
||||
|
||||
```sh
|
||||
$ kompose --file ./examples/docker-guestbook.yml up
|
||||
We are going to create Kubernetes deployments and services for your Dockerized application.
|
||||
If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
|
||||
|
||||
INFO Successfully created service: redis-master
|
||||
INFO Successfully created service: redis-slave
|
||||
INFO Successfully created service: frontend
|
||||
INFO Successfully created deployment: redis-master
|
||||
INFO Successfully created deployment: redis-slave
|
||||
INFO Successfully created deployment: frontend
|
||||
|
||||
Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods' for details.
|
||||
|
||||
$ kubectl get deployment,svc,pods
|
||||
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
||||
deployment.extensions/frontend 1 1 1 1 4m
|
||||
deployment.extensions/redis-master 1 1 1 1 4m
|
||||
deployment.extensions/redis-slave 1 1 1 1 4m
|
||||
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/frontend ClusterIP 10.0.174.12 <none> 80/TCP 4m
|
||||
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 13d
|
||||
service/redis-master ClusterIP 10.0.202.43 <none> 6379/TCP 4m
|
||||
service/redis-slave ClusterIP 10.0.1.85 <none> 6379/TCP 4m
|
||||
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
pod/frontend-2768218532-cs5t5 1/1 Running 0 4m
|
||||
pod/redis-master-1432129712-63jn8 1/1 Running 0 4m
|
||||
pod/redis-slave-2504961300-nve7b 1/1 Running 0 4m
|
||||
```
|
||||
|
||||
<!--
|
||||
**Note**:
|
||||
- You must have a running Kubernetes cluster with a pre-configured kubectl context.
|
||||
- Only deployments and services are generated and deployed to Kubernetes. If you need different kind of resources, use the `kompose convert` and `kubectl create -f` commands instead.
|
||||
-->
|
||||
|
||||
**注意**:
|
||||
|
||||
- 您必须有一个运行正常的 Kubernetes 集群,该集群具有预先配置的 kubectl 上下文。
|
||||
- 此操作仅生成 Deployment 和 Service 对象并将其部署到 Kubernetes。如果需要部署其他不同类型的资源,请使用 `kompose convert` 和 `kubectl create -f` 命令。
|
||||
|
||||
|
||||
### OpenShift
|
||||
```sh
|
||||
$ kompose --file ./examples/docker-guestbook.yml --provider openshift up
|
||||
We are going to create OpenShift DeploymentConfigs and Services for your Dockerized application.
|
||||
If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead.
|
||||
|
||||
INFO Successfully created service: redis-slave
|
||||
INFO Successfully created service: frontend
|
||||
INFO Successfully created service: redis-master
|
||||
INFO Successfully created deployment: redis-slave
|
||||
INFO Successfully created ImageStream: redis-slave
|
||||
INFO Successfully created deployment: frontend
|
||||
INFO Successfully created ImageStream: frontend
|
||||
INFO Successfully created deployment: redis-master
|
||||
INFO Successfully created ImageStream: redis-master
|
||||
|
||||
Your application has been deployed to OpenShift. You can run 'oc get dc,svc,is' for details.
|
||||
|
||||
$ oc get dc,svc,is
|
||||
NAME REVISION DESIRED CURRENT TRIGGERED BY
|
||||
dc/frontend 0 1 0 config,image(frontend:v4)
|
||||
dc/redis-master 0 1 0 config,image(redis-master:e2e)
|
||||
dc/redis-slave 0 1 0 config,image(redis-slave:v1)
|
||||
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
svc/frontend 172.30.46.64 <none> 80/TCP 8s
|
||||
svc/redis-master 172.30.144.56 <none> 6379/TCP 8s
|
||||
svc/redis-slave 172.30.75.245 <none> 6379/TCP 8s
|
||||
NAME DOCKER REPO TAGS UPDATED
|
||||
is/frontend 172.30.12.200:5000/fff/frontend
|
||||
is/redis-master 172.30.12.200:5000/fff/redis-master
|
||||
is/redis-slave 172.30.12.200:5000/fff/redis-slave v1
|
||||
```
|
||||
|
||||
<!--
|
||||
**Note**:
|
||||
- You must have a running OpenShift cluster with a pre-configured `oc` context (`oc login`)
|
||||
-->
|
||||
|
||||
**注意**:
|
||||
|
||||
- 您必须有一个运行正常的 OpenShift 集群,该集群具有预先配置的 `oc` 上下文 (`oc login`)。
|
||||
|
||||
## `kompose down`
|
||||
|
||||
<!--
|
||||
Once you have deployed "composed" application to Kubernetes, `$ kompose down` will help you to take the application out by deleting its deployments and services. If you need to remove other resources, use the 'kubectl' command.
|
||||
-->
|
||||
|
||||
您一旦将"复合(composed)" 应用部署到 Kubernetes,`$ kompose down` 命令将能帮您通过删除 Deployment 和 Service 对象来删除应用。如果需要删除其他资源,请使用 'kubectl' 命令。
|
||||
|
||||
```sh
|
||||
$ kompose --file docker-guestbook.yml down
|
||||
INFO Successfully deleted service: redis-master
|
||||
INFO Successfully deleted deployment: redis-master
|
||||
INFO Successfully deleted service: redis-slave
|
||||
INFO Successfully deleted deployment: redis-slave
|
||||
INFO Successfully deleted service: frontend
|
||||
INFO Successfully deleted deployment: frontend
|
||||
```
|
||||
|
||||
<!--
|
||||
**Note**:
|
||||
- You must have a running Kubernetes cluster with a pre-configured kubectl context.
|
||||
## Build and Push Docker Images
|
||||
Kompose supports both building and pushing Docker images. When using the `build` key within your Docker Compose file, your image will:
|
||||
- Automatically be built with Docker using the `image` key specified within your file
|
||||
- Be pushed to the correct Docker repository using local credentials (located at `.docker/config`)
|
||||
Using an [example Docker Compose file](https://raw.githubusercontent.com/kubernetes/kompose/master/examples/buildconfig/docker-compose.yml):
|
||||
-->
|
||||
|
||||
**注意**:
|
||||
|
||||
- 您必须有一个运行正常的 Kubernetes 集群,该集群具有预先配置的 kubectl 上下文。
|
||||
|
||||
## 构建和推送 Docker 镜像
|
||||
|
||||
Kompose 支持构建和推送 Docker 镜像。如果 Docker Compose 文件中使用了 `build` 关键字,您的镜像将会:
|
||||
|
||||
- 使用文档中指定的 `image` 键自动构建 Docker 镜像
|
||||
- 使用本地凭据推送到正确的 Docker 仓库
|
||||
|
||||
使用 [Docker Compose 文件示例](https://raw.githubusercontent.com/kubernetes/kompose/master/examples/buildconfig/docker-compose.yml)
|
||||
|
||||
```yaml
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
foo:
|
||||
build: "./build"
|
||||
image: docker.io/foo/bar
|
||||
```
|
||||
|
||||
<!--
|
||||
Using `kompose up` with a `build` key:
|
||||
-->
|
||||
|
||||
使用带有 `build` 键的 `kompose up` 命令:
|
||||
|
||||
```none
|
||||
$ kompose up
|
||||
INFO Build key detected. Attempting to build and push image 'docker.io/foo/bar'
|
||||
INFO Building image 'docker.io/foo/bar' from directory 'build'
|
||||
INFO Image 'docker.io/foo/bar' from directory 'build' built successfully
|
||||
INFO Pushing image 'foo/bar:latest' to registry 'docker.io'
|
||||
INFO Attempting authentication credentials 'https://index.docker.io/v1/
|
||||
INFO Successfully pushed image 'foo/bar:latest' to registry 'docker.io'
|
||||
INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
|
||||
|
||||
INFO Deploying application in "default" namespace
|
||||
INFO Successfully created Service: foo
|
||||
INFO Successfully created Deployment: foo
|
||||
|
||||
Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.
|
||||
```
|
||||
|
||||
<!--
|
||||
In order to disable the functionality, or choose to use BuildConfig generation (with OpenShift) `--build (local|build-config|none)` can be passed.
|
||||
-->
|
||||
|
||||
要想禁用该功能,或者使用 BuildConfig 中的版本(在 OpenShift 中),可以通过传递 `--build (local|build-config|none)` 参数来实现。
|
||||
|
||||
```sh
|
||||
# Disable building/pushing Docker images
|
||||
$ kompose up --build none
|
||||
|
||||
# Generate Build Config artifacts for OpenShift
|
||||
$ kompose up --provider openshift --build build-config
|
||||
```
|
||||
|
||||
<!--
|
||||
## Alternative Conversions
|
||||
The default `kompose` transformation will generate Kubernetes [Deployments](/docs/concepts/workloads/controllers/deployment/) and [Services](/docs/concepts/services-networking/service/), in yaml format. You have alternative option to generate json with `-j`. Also, you can alternatively generate [Replication Controllers](/docs/concepts/workloads/controllers/replicationcontroller/) objects, [Daemon Sets](/docs/concepts/workloads/controllers/daemonset/), or [Helm](https://github.com/helm/helm) charts.
|
||||
-->
|
||||
|
||||
## 其他转换方式
|
||||
|
||||
默认的 `kompose` 转换会生成 yaml 格式的 Kubernetes [Deployment](/docs/concepts/workloads/controllers/deployment/) 和 [Service](/docs/concepts/services-networking/service/) 对象。
|
||||
您可以选择通过 `-j` 参数生成 json 格式的对象。
|
||||
您也可以替换生成 [Replication Controllers](/docs/concepts/workloads/controllers/replicationcontroller/) 对象、[Daemon Sets](/docs/concepts/workloads/controllers/daemonset/) 或 [Helm](https://github.com/helm/helm) charts。
|
||||
|
||||
```sh
|
||||
$ kompose convert -j
|
||||
INFO Kubernetes file "redis-svc.json" created
|
||||
INFO Kubernetes file "web-svc.json" created
|
||||
INFO Kubernetes file "redis-deployment.json" created
|
||||
INFO Kubernetes file "web-deployment.json" created
|
||||
```
|
||||
|
||||
<!--
|
||||
The `*-deployment.json` files contain the Deployment objects.
|
||||
-->
|
||||
|
||||
`*-deployment.json` 文件中包含 Deployment 对象。
|
||||
|
||||
```sh
|
||||
$ kompose convert --replication-controller
|
||||
INFO Kubernetes file "redis-svc.yaml" created
|
||||
INFO Kubernetes file "web-svc.yaml" created
|
||||
INFO Kubernetes file "redis-replicationcontroller.yaml" created
|
||||
INFO Kubernetes file "web-replicationcontroller.yaml" created
|
||||
```
|
||||
|
||||
<!--
|
||||
The `*-replicationcontroller.yaml` files contain the Replication Controller objects. If you want to specify replicas (default is 1), use `--replicas` flag: `$ kompose convert --replication-controller --replicas 3`
|
||||
-->
|
||||
|
||||
`*-replicationcontroller.yaml` 文件包含 Replication Controller 对象。如果您想指定副本数(默认为 1),可以使用 `--replicas` 参数:`$ kompose convert --replication-controller --replicas 3`
|
||||
|
||||
```sh
|
||||
$ kompose convert --daemon-set
|
||||
INFO Kubernetes file "redis-svc.yaml" created
|
||||
INFO Kubernetes file "web-svc.yaml" created
|
||||
INFO Kubernetes file "redis-daemonset.yaml" created
|
||||
INFO Kubernetes file "web-daemonset.yaml" created
|
||||
```
|
||||
|
||||
<!--
|
||||
The `*-daemonset.yaml` files contain the Daemon Set objects
|
||||
If you want to generate a Chart to be used with [Helm](https://github.com/kubernetes/helm) simply do:
|
||||
-->
|
||||
|
||||
`*-daemonset.yaml` 文件包含 Daemon Set 对象。
|
||||
|
||||
如果您想生成 [Helm](https://github.com/kubernetes/helm) 可用的 Chart,只需简单的执行下面的命令:
|
||||
|
||||
```sh
|
||||
$ kompose convert -c
|
||||
INFO Kubernetes file "web-svc.yaml" created
|
||||
INFO Kubernetes file "redis-svc.yaml" created
|
||||
INFO Kubernetes file "web-deployment.yaml" created
|
||||
INFO Kubernetes file "redis-deployment.yaml" created
|
||||
chart created in "./docker-compose/"
|
||||
|
||||
$ tree docker-compose/
|
||||
docker-compose
|
||||
├── Chart.yaml
|
||||
├── README.md
|
||||
└── templates
|
||||
├── redis-deployment.yaml
|
||||
├── redis-svc.yaml
|
||||
├── web-deployment.yaml
|
||||
└── web-svc.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
The chart structure is aimed at providing a skeleton for building your Helm charts.
|
||||
## Labels
|
||||
`kompose` supports Kompose-specific labels within the `docker-compose.yml` file in order to explicitly define a service's behavior upon conversion.
|
||||
- `kompose.service.type` defines the type of service to be created.
|
||||
For example:
|
||||
-->
|
||||
|
||||
这个图标结构旨在为构建 Helm Chart 提供框架。
|
||||
|
||||
## 标签
|
||||
|
||||
`kompose` 支持 `docker-compose.yml` 文件中用于 Kompose 的标签,以便在转换时明确定义 Service 的行为。
|
||||
|
||||
- `kompose.service.type` 定义要创建的 Service 类型。
|
||||
|
||||
|
||||
|
||||
```yaml
|
||||
version: "2"
|
||||
services:
|
||||
nginx:
|
||||
image: nginx
|
||||
dockerfile: foobar
|
||||
build: ./foobar
|
||||
cap_add:
|
||||
- ALL
|
||||
container_name: foobar
|
||||
labels:
|
||||
kompose.service.type: nodeport
|
||||
```
|
||||
|
||||
<!--
|
||||
- `kompose.service.expose` defines if the service needs to be made accessible from outside the cluster or not. If the value is set to "true", the provider sets the endpoint automatically, and for any other value, the value is set as the hostname. If multiple ports are defined in a service, the first one is chosen to be the exposed.
|
||||
- For the Kubernetes provider, an ingress resource is created and it is assumed that an ingress controller has already been configured.
|
||||
- For the OpenShift provider, a route is created.
|
||||
For example:
|
||||
-->
|
||||
|
||||
- `kompose.service.expose` 定义 是否允许从集群外部访问 Service。如果该值被设置为 "true",提供程序将自动设置端点,对于任何其他值,该值将被设置为主机名。如果在 Service 中定义了多个端口,则选择第一个端口作为公开端口。
|
||||
- 对于 Kubernetes 驱动程序,创建了一个 Ingress 资源,并且假定已经配置了相应的 Ingress 控制器。
|
||||
- 对于 OpenShift 驱动程序, 创建一个 route。
|
||||
|
||||
例如:
|
||||
|
||||
```yaml
|
||||
version: "2"
|
||||
services:
|
||||
web:
|
||||
image: tuna/docker-counter23
|
||||
ports:
|
||||
- "5000:5000"
|
||||
links:
|
||||
- redis
|
||||
labels:
|
||||
kompose.service.expose: "counter.example.com"
|
||||
redis:
|
||||
image: redis:3.0
|
||||
ports:
|
||||
- "6379"
|
||||
```
|
||||
|
||||
<!--
|
||||
The currently supported options are:
|
||||
| Key | Value |
|
||||
|----------------------|-------------------------------------|
|
||||
| kompose.service.type | nodeport / clusterip / loadbalancer |
|
||||
| kompose.service.expose| true / hostname |
|
||||
-->
|
||||
|
||||
当前支持的选项有:
|
||||
|
||||
| 键 | 值 |
|
||||
|----------------------|-------------------------------------|
|
||||
| kompose.service.type | nodeport / clusterip / loadbalancer |
|
||||
| kompose.service.expose| true / hostname |
|
||||
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
The `kompose.service.type` label should be defined with `ports` only, otherwise `kompose` will fail.
|
||||
-->
|
||||
`kompose.service.type` 标签应该只用`ports`来定义,否则 `kompose` 会失败。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Restart
|
||||
If you want to create normal pods without controllers you can use `restart` construct of docker-compose to define that. Follow table below to see what happens on the `restart` value.
|
||||
-->
|
||||
|
||||
## 重启
|
||||
|
||||
如果你想创建没有控制器的普通 Pod,可以使用 docker-compose 的 `restart` 结构来定义它。请参考下表了解 `restart` 的不同参数。
|
||||
|
||||
<!--
|
||||
| `docker-compose` `restart` | object created | Pod `restartPolicy` |
|
||||
|----------------------------|-------------------|---------------------|
|
||||
| `""` | controller object | `Always` |
|
||||
| `always` | controller object | `Always` |
|
||||
| `on-failure` | Pod | `OnFailure` |
|
||||
| `no` | Pod | `Never` |
|
||||
-->
|
||||
|
||||
| `docker-compose` `restart` | 创建的对象 | Pod `restartPolicy` |
|
||||
|----------------------------|-------------------|---------------------|
|
||||
| `""` | 控制器对象 | `Always` |
|
||||
| `always` | 控制器对象 | `Always` |
|
||||
| `on-failure` | Pod | `OnFailure` |
|
||||
| `no` | Pod | `Never` |
|
||||
|
||||
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
The controller object could be `deployment` or `replicationcontroller`, etc.
|
||||
-->
|
||||
控制器对象可以是 `deployment` 或 `replicationcontroller` 等。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
For e.g. `pival` service will become pod down here. This container calculated value of `pi`.
|
||||
-->
|
||||
|
||||
例如,`pival` Service 将在这里变成 Pod。这个容器的计算值为 `pi`。
|
||||
|
||||
```yaml
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
pival:
|
||||
image: perl
|
||||
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
|
||||
restart: "on-failure"
|
||||
```
|
||||
|
||||
<!--
|
||||
### Warning about Deployment Config's
|
||||
If the Docker Compose file has a volume specified for a service, the Deployment (Kubernetes) or DeploymentConfig (OpenShift) strategy is changed to "Recreate" instead of "RollingUpdate" (default). This is done to avoid multiple instances of a service from accessing a volume at the same time.
|
||||
-->
|
||||
|
||||
### 关于 Deployment Config 的提醒
|
||||
|
||||
如果 Docker Compose 文件中为服务声明了卷,Deployment (Kubernetes) 或 DeploymentConfig (OpenShift) 的策略会从 "RollingUpdate" (默认) 变为 "Recreate"。
|
||||
这样做的目的是为了避免服务的多个实例同时访问卷。
|
||||
|
||||
<!--
|
||||
If the Docker Compose file has service name with `_` in it (eg.`web_service`), then it will be replaced by `-` and the service name will be renamed accordingly (eg.`web-service`). Kompose does this because "Kubernetes" doesn't allow `_` in object name.
|
||||
Please note that changing service name might break some `docker-compose` files.
|
||||
-->
|
||||
|
||||
如果 Docker Compose 文件中的服务名包含 `_` (例如 `web_service`),那么将会被替换为 `-`,服务也相应的会重命名(例如 `web-service`)。
|
||||
Kompose 这样做的原因是 "Kubernetes" 不允许对象名称中包含 `_`。
|
||||
|
||||
<!--
|
||||
## Docker Compose Versions
|
||||
Kompose supports Docker Compose versions: 1, 2 and 3. We have limited support on versions 2.1 and 3.2 due to their experimental nature.
|
||||
A full list on compatibility between all three versions is listed in our [conversion document](https://github.com/kubernetes/kompose/blob/master/docs/conversion.md) including a list of all incompatible Docker Compose keys.
|
||||
-->
|
||||
|
||||
## Docker Compose 版本
|
||||
|
||||
Kompose 支持的 Docker Compose 版本包括:1、2 和 3。有限支持 2.1 和 3.2 版本,因为它们还在实验阶段。
|
||||
|
||||
所有三个版本的兼容性列表请查看我们的 [转换文档](https://github.com/kubernetes/kompose/blob/master/docs/conversion.md),文档中列出了所有不兼容的 Docker Compose 关键字。
|
||||
|
||||
{{% /capture %}}
|
||||
Reference in New Issue
Block a user