我一直在用type:deployment创建pod,但我看到一些文档使用type:pod,更具体地说,多容器pod的文档:
apiVersion: v1
kind: Pod
metadata:
name: ""
labels:
name: ""
namespace: ""
annotations: []
generateName: ""
spec:
? "// See 'The spec schema' for details."
: ~
但是要创建pod,我可以使用部署类型:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ""
spec:
replicas: 3
template:
metadata:
labels:
app: ""
spec:
containers:
etc
我注意到pod文档说:
The create command can be used to create a pod directly, or it can
create a pod or pods through a Deployment. It is highly recommended
that you use a Deployment to create your pods. It watches for failed
pods and will start up new pods as required to maintain the specified
number. If you don’t want a Deployment to monitor your pod (e.g. your
pod is writing non-persistent data which won’t survive a restart, or
your pod is intended to be very short-lived), you can create a pod
directly with the create command.
Note: We recommend using a Deployment to create pods. You should use
the instructions below only if you don’t want to create a Deployment.
但这就提出了一个问题:豆荚适合哪一种?你能在部署中引用pod吗?我不知道该怎么办。看起来你从pods中得到的是一些额外的元数据,但没有任何部署选项,如副本或重启策略。一个不保存数据的吊舱在重启后还能存活,这有什么用呢?我认为我能够创建一个多容器pod部署以及。
在Kubernetes中,我们可以使用不同类型的API对象来部署我们的工作负载,比如Pods、Deployment、ReplicaSet、ReplicationController和StatefulSets。
这些pod是Kubernetes中最小的可部署单元。任何在Kubernetes中运行的工作负载/应用程序都必须在Pod的容器部分中运行。Pod可以在其中运行多个容器(即多个应用程序)。Pod是一个或多个运行容器之上的包装器。使用Pod, kubernetes可以控制、监控和操作容器。
Now using stand alone Pods we can't do lot of things. We can't change configurations, volumes inside Pods. We can't restart the Pod if one is down.
So there is another API Object called Deployment comes into picture which maintains the desired state (how many instances, how much compute resource application uses) of the application. The Deployment maintaines multiple instances of same application by running multiple Pods. Deployments unlike Pods are mutable. Deployments uses another API Object called ReplicaSet to maintain the desired state. Deployments through ReplicaSet spawns another Pod if one is down.
所以Pod在容器中运行应用程序。部署运行Pods并维护应用程序所需的状态。
也许这个例子对初学者会有帮助!!
1)列出PODs
controlplane $ kubectl -n my-namespace get pods
NAME READY STATUS RESTARTS AGE
mysql 1/1 Running 0 92s
webapp-mysql-75dfdf859f-9c54j 1/1 Running 0 92s
2)删除web-app pode -这是使用部署创建
controlplane $ kubectl -n my-namespace delete pod webapp-mysql-75dfdf859f-9c54j
pod "webapp-mysql-75dfdf859f-9c54j" deleted
3)列出PODs(你可以看到,它是自动重新创建的)
controlplane $ kubectl -n my-namespace get pods
NAME READY STATUS RESTARTS AGE
mysql 1/1 Running 0 2m42s
webapp-mysql-75dfdf859f-mqrcx 1/1 Running 0 45s
4)删除直接创建的mysql POD(无需部署)
controlplane $ kubectl -n my-namespace delete pod mysql
pod "mysql" deleted
5)列出POD(你可以看到mysql POD永远丢失了)
controlplane $ kubectl -n my-namespace get pods
NAME READY STATUS RESTARTS AGE
webapp-mysql-75dfdf859f-mqrcx 1/1 Running 0 76s
Kubernetes有三种你应该知道的对象类型:
pod -运行一个或多个紧密相关的容器
服务——在Kubernetes集群中建立网络
部署——维护一组相同的pod,确保它们具有正确的配置,并且存在正确的数量。
豆荚:
运行一组容器
适合一次性开发目的
很少直接用于生产
部署:
运行一组相同的豆荚
监视每个pod的状态,必要时进行更新
对开发者有利
有利于生产
我同意其他的答案,忘掉Pods,使用Deployment。为什么?看看第二个要点,它监视每个pod的状态,并根据需要进行更新。
因此,与其纠结于这样的错误消息:
禁止:pod更新不能改变spec.containers[*].image以外的字段
因此,只需重构或完全重新创建您的Pod到一个部署,创建一个Pod来做您需要做的事情。使用Deployment,您可以更改任何您想更改的配置部分,并且不必担心看到错误消息。