问题描述
我刚刚开始使用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 -f
或kubectl 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.
- 使用生成器(运行,公开)
- 使用命令式方式(创建)
- 使用声明性方式(应用)
以上所有方式都有不同的目的和简单性.例如,如果您想快速检查容器是否按预期工作,则可以使用 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和Pod是解决不同问题的不同层.所有这些概念都为k8提供了灵活性.
Deployment, ReplicaSet and Pods are different layers which solve different problems.All of these concepts provide flexibility to k8s.
- 荚:它确保相关的容器在一起并提供效率.
- 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运行与创建和应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!