Kubernetes简单声明式管理 [英] Kubernetes Simple Declarative Management

查看:46
本文介绍了Kubernetes简单声明式管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有比自己编写模板文件更简单的声明式管理的方法?

Is there a way for more simple Declarative Management than writing template files myself?

例如使用kubectl命令创建模板文件,然后在这些模板上使用 kubectl apply ?

E.g. create the template files with kubectl command and then use kubectl apply on those templates?

kubectl create deployment my-app --image=nginx:latest --replicas=3 --port=8080 --dry-run=client --output=yaml > my-deployment.yaml
kubectl create service loadbalancer my-app --tcp=80:8080 --dry-run=client -o=yaml > my-service.yaml

然后应用生成的模板文件:

And after this apply the generated template files:

kubectl apply -f .

可以使用这种方法进行生产吗?还是认为这不是一个好习惯?

Is it OK to use such approach for production? Or it is considered not a good practice?

推荐答案

虽然编写单个YAML清单很普遍自己,如您所显示的那样,单独应用它们是不常见的在你的问题.在我工作的地方,我们使用 Kustomize 来管理我们的表现这是一个汇编清单的工具进入配置,然后使用 kubectl apply 一次全部应用(其他人使用 Helm ,但是我对该工具没有任何经验.

While it's quite common to write the individual YAML manifests yourself, it's less common to apply them individually as you've shown in your question. Where I work, we use Kustomize to manage our manifests; this is a tool that assembles a collection of manifests into a configuration which you then apply all at once using kubectl apply (other folks use Helm, but I don't have any experience with that tool).

文档中有很多示例,但是对于您的示例,您可以执行以下操作:

There are lots of examples in the documentation, but for your example, you might do something like this:

  • 将部署清单放入 my-deployment.yaml

将您的服务清单放入 my-service.yaml

创建具有以下内容的文件 kustomization.yaml :

Create a file kustomization.yaml with the following content:

resources:
  - my-deployment.yaml
  - my-service.yaml

要在集群中创建或更新资源,请运行:

To create or update your resources in the cluster, you run:

kustomize build | kubectl apply -f-

Kustomize具有许多用于生成诸如以下内容的选项文件中的 ConfigMaps Secrets ,用于创建层次结构可以覆盖清单的部分的配置带有修改后的内容等.

Kustomize has a number of options for generating things like ConfigMaps and Secrets from files, for creating a hierarchical configuration in which you can override portions of your manifests with modified content, etc.

请注意, kubectl 中实际上内置了Kustomize版本命令;对于上面的示例,您可以简单地运行:

Note that a version of Kustomize is actually build into the kubectl command; for the above example, you could have simply run:

kubectl apply -k .

kubectl 中内置的Kustomize版本比独立版本稍旧,但是对于简单的配置,它就可以正常工作.

The version of Kustomize built into kubectl is a little older than the standalone version, but for simple configurations it works just fine.

这篇关于Kubernetes简单声明式管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆