Files
website/content/zh/docs/tutorials/object-management-kubectl/object-management.md
T
Zach Corleissen abcee2dccd Update localization guidelines (#10485)
* Update localization guidelines for language labels

Continuing work

Continuing work

Continuing work

More work in progress

Add local OWNERS folders

Add an OWNERS file to Chinese

Remove shortcode for repos

Add Japanese

Alphabetize languages, change weights accordingly

More updates

Add Korean in Korean

Add English to languageName

Feedback from gochist

Move Chinese content from cn/ to zh/

Move OWNERS from cn/ to zh/

Resolve merge conflicts by updating from master

Add files back in to prep for resolution

After rebase on upstream/master, remove files

Review and update localization guidelines

Feedback from gochist, tnir, cstoku

Add a trailing newline to content/ja/OWNERS

Add a trailing newline to content/zh/OWNERS

Drop requirement for GH repo project

Clarify language about forks/branches

Edits and typos

Remove a shortcode specific to a multi-repo language setup

Update aliases and owners

Add explicit OWNERS for content/en

Migrate content from Chinese repo, update regex in config.toml

Remove untranslated strings

Add trailing newline to content/en/OWNERS

Add trailing newlines to OWNERS files

add Jaguar project description (#10433)

* add Jaguar project description

[Jaguar](https://gitlab.com/sdnlab/jaguar) is an open source solution for Kubernetes's network based on OpenDaylight.
Jaguar provides overlay network using vxlan and Jaguar CNIPlugin provides one IP address per pod.

* Minor newline tweak

blog post for azure vmss (#10538)

Add microk8s to pick-right-solution.md (#10542)

* Add microk8s to pick-right-solution.md

Microk8s is a single-command installation of upstream Kubernetes on any Linux and should be included in the list of local-machine solutions.

* capitalized Istio

Add microk8s to foundational.md (#10543)

* Add microk8s to foundational.md

Adding microk8s as credible and stable alternative to get started with Kubernetes on a local machine. This is especially attractive for those not wanting to incur the overhead of running a VM for a local cluster.

* Update foundational.md

Thank you for your suggestions! LMK if this works now?

* Rewrote first paragraph

And included a bullet list of features of microk8s

* Copyedit

fix typo (#10545)

Fix the kubectl subcommands links. (#10550)

Signed-off-by: William Zhang <warmchang@outlook.com>

Fix command issue (#10515)

Signed-off-by: mooncake <xcoder@tenxcloud.com>

remove imported community files per issue 10184 (#10501)

networking.md: Markdown fix (#10498)

Fix front matter, federation command-line tools (#10500)

Clean up glossary entry (#10399)

update slack link (#10536)

typo in StatefulSet docs (#10558)

fix discription about horizontal pod autoscale (#10557)

Remove redundant symbols (#10556)

Fix issue #10520 (#10554)

Signed-off-by: William Zhang <warmchang@outlook.com>

Update api-concepts.md (#10534)

Revert "Fix command issue (#10515)"

This reverts commit c02a7fb9f9.

Update memory-constraint-namespace.md (#10530)

update memory request to 100MiB corresponding the yaml content

Blog: Introducing Volume Snapshot Alpha for Kubernetes (#10562)

* blog post for azure vmss

* snapshot blog post

Resolve merge conflicts in OWNERS*

Minor typo fix (#10567)

Not sure what's supposed to be here, proposing removing it.

* Feedback from gochist

Tweaks to feedback

* Feedback from ClaudiaJKang
2018-10-12 14:25:01 -07:00

5.4 KiB

title, content_template
title content_template
Kubernetes 对象管理 templates/concept

{{% capture overview %}} kubectl 命令行工具支持 Kubernetes 对象几种不同的创建和管理方法。本文档简要介绍了这些方法. {{% /capture %}}

{{% capture body %}}

管理技巧

警告: Kubernetes 对象应该只使用一种技术进行管理。混合使用不同的技术,会导致相同对象出现未定义的行为。

管理技术 操作 推荐环境 支持撰写 学习曲线
命令式的方式 活动对象 开发项目 1+ 最低
命令式对象配置 单文件 生产项目 1 中等
声明式对象配置 文件目录 生产项目 1+ 最高

命令式的方式

当使用命令式的命令时,用户直接对集群中的活动对象进行操作。用户提供 kubectl 命令的参数或标记进行操作。

这是在集群中启动或运行一次性任务的最简单的方法。因为这种技术直接在活动对象上运行,所以它没有提供以前配置的历史记录。

例子

通过创建 Deployment 对象来运行 nginx 容器的实例:

kubectl run nginx --image nginx

使用不同的语法做同样的事情:

kubectl create deployment nginx --image nginx

权衡

与对象配置相比的优点:

  • 命令简单易学,易于记忆。
  • 命令只需要一个步骤即可对群集进行更改。

与对象配置相比的缺点:

  • 命令不与变更审核流程整合。
  • 命令不提供与更改相关联的审计跟踪。
  • 除了活动对象之外,命令不提供记录来源。
  • 命令不提供用于创建新对象的模板。

命令式对象配置

在命令式对象配置中,kubectl 命令指定操作(创建,替换等),可选标志和至少一个文件名称。指定的文件必须包含对象的完整定义以 YAML 或 JSON 格式。

请参阅参考资源 查看有关对象定义的更多细节。

警告: 命令式 replace 命令用新提供的命令替换现有资源规格,将对配置文件中缺少的对象的所有更改都丢弃。这种方法不应更新与配置文件无关的资源类型。例如,LoadBalancer 类型的服务使其 externalIPs 字段与集群的配置无关。

例子

创建对象定义配置文件:

kubectl create -f nginx.yaml

删除两个配置文件中定义的对象:

kubectl delete -f nginx.yaml -f redis.yaml

通过覆写实时配置更新配置文件中定义的对象:

kubectl replace -f nginx.yaml

权衡

与命令式的命令相比的优点:

  • 对象配置可以存储在源码控制系统中,如Git。
  • 对象配置可以与进程集成,例如在推送和审计跟踪之前查看更改。
  • 对象配置提供了一个用于创建新对象的模板。

与命令式的命令相比的缺点:

  • 对象配置需要对对象模式有基本的了解。
  • 对象配置需要编写 YAML 文件的附加步骤。

与声明式对象配置相比的优势:

  • 命令对象配置行为更简单易懂。
  • 至于 Kubernetes 1.5 版本,命令式对象配置更为成熟。

与声明式对象配置相比的缺点:

  • 命令对象配置最适合于文件,而不是目录。
  • 活动对象的更新必须反映在配置文件中,否则在下次更替时将丢失。

声明式对象配置

当使用声明式对象配置时,用户对本地存储的对象配置文件进行操作,但是用户没有定义要对文件执行的操作。通过 kubectl 自动检测每个对象进行创建、更新和删除操作。这样可以在目录层级上工作,因为不同的对象可能需要不同的操作。

注意: 声明式对象配置保留由其他对象进行的更改,即使更改未合并到对象配置文件中。这可以通过使用 patch API 操作来写入观察到的差异,而不是使用replace API 操作来替换整个对象的配置。

例子

处理configs 目录中的所有对象配置文件,创建或修补(patch)活动对象:

kubectl apply -f configs/

递归处理目录:

kubectl apply -R -f configs/

权衡

与命令式对象配置相比的优点:

  • 直接对活动对象进行的更改将被保留,即使它们未被并入到配置文件中。
  • 声明式对象配置更好地支持目录操作,并自动检测每个对象的操作类型 (创建、修补,删除)。

与命令式对象配置相比的缺点:

  • 声明式对象配置在意外情况下难以调试和了解结果。
  • 使用差异的部分更新会创建复杂的合并和补丁操作。

{{% /capture %}}

{{% capture whatsnext %}}

{{< comment >}} {{< /comment >}} {{% /capture %}}