我一直在用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部署以及。
也许这个例子对初学者会有帮助!!
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对象,比如deployment, replica-sets, statefulsets, daemonsets,它都会创建pod。
如上所述,部署根据部署对象中提到的所需状态创建pod。例如,你需要一个应用程序的5个副本,你在部署清单中提到了副本:5。现在,部署控制器负责为给定的应用程序创建5个相同的副本(不少也不多),其中包含所有元数据,如RBAC策略、网络策略、标签、注释、健康检查、资源配额、污染/容差等,并与它创建的每个pod关联。
在某些情况下,当你想要创建pod时,例如,如果你正在运行一个测试sidecar,你不需要永远运行应用程序,你不需要多个副本,当你想在pod适合的情况下执行时,你就运行应用程序。例如helm test,这是一个pod定义,它指定了一个包含要运行的给定命令的容器。
也许这个例子对初学者会有帮助!!
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中,我们可以使用不同类型的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并维护应用程序所需的状态。