kubernetes - kubectl run vs create and apply [英] kubernetes - kubectl run vs create and apply

查看:33
本文介绍了kubernetes - kubectl run vs create and apply的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 kubernetes 并使用 kops 在 AWS 上设置集群.在我阅读(并尝试)的许多示例中,都会有如下命令:

I'm just getting started with kubernetes and setting up a cluster on AWS using kops. In many of the examples I read (and try), there will be commands like:

kubectl run my-app --image=mycompany/myapp:latest --replicas=1 --port=8080

kubectl expose deployment my=app --port=80 --type=LoadBalancer

这似乎在幕后做了几件事,我可以查看使用 kubectl edit deployment 创建的清单文件,等等 但是,我看到许多示例,人们通过以下方式创建清单文件手,并使用诸如 kubectl create -fkubectl apply -f

This seems to do several things behind the scenes, and I can view the manifest files created using kubectl edit deployment, and so forth However, i see many examples where people are creating the manifest files by hand, and using commands like kubectl create -f or kubectl apply -f

我是否正确地假设两种方法都实现了相同的目标,但通过自己创建清单文件,您可以进行更精细的控制?

Am I correct in assuming that both approaches accomplish the same goals, but that by creating the manifest files yourself, you have a finer grain of control?

那么我是否必须自己创建 Service、ReplicationController 和 Pod 规范?

Would I then have to be creating Service, ReplicationController, and Pod specs myself?

最后,如果您自己创建清单文件,就存储这些文件而言,人们通常如何构建他们的项目?他们只是在他们正在部署的项目旁边的一个目录中吗?

Lastly, if you create the manifest files yourself, how do people generally structure their projects as far as storing these files? Are they simply in a directory alongside the project they are deploying?

推荐答案

根本问题是如何将所有 K8s 对象应用到 k8s 集群中.有几种方法可以完成这项工作.

The fundamental question is how to apply all of the K8s objects into the k8s cluster. There are several ways to do this job.

  • 使用生成器(运行、暴露)
  • 使用命令式方式(创建)
  • 使用声明方式(Apply)

以上所有方式都有不同的目的和简单性.例如,如果您想快速检查容器是否按预期工作,那么您可以使用 Generators .

All of the above ways have a different purpose and simplicity. For instance, If you want to check quickly whether the container is working as you desired then you might use Generators .

如果您想对 k8s 对象进行版本控制,那么最好使用 声明式 方式,这有助于我们确定 k8s 对象中数据的准确性.

If you want to version control the k8s object then it's better to use declarative way which helps us to determine the accuracy of data in k8s objects.

Deployment、ReplicaSet 和 Pods 是解决不同问题的不同层.所有这些概念都为 k8s 提供了灵活性.

Deployment, ReplicaSet and Pods are different layers which solve different problems.All of these concepts provide flexibility to k8s.

  • Pods:确保相关容器在一起并提供效率.
  • ReplicaSet:确保 k8s 集群具有理想的 Pod 副本
  • 部署:确保您可以拥有不同版本的 Pod 并提供回滚到先前版本的能力

最后,这取决于您希望如何使用这些概念或方法的用例.这不是关于哪个好或哪个坏.

Lastly, It depends on use case how you want to use these concepts or methodology. It's not about which is good or which is bad.

这篇关于kubernetes - kubectl run vs create and apply的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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