[英]kubernetes “n” independent pods with identity 1 to n
Requirement 1 (routes): I need to be able to route to "n" independent Kubernetes deployments. 要求1(路由):我需要能够路由到“ n”个独立的Kubernetes部署。 Such as: 如:
Each building is receiving traffic that is independent of the others. 每个建筑物都在接收彼此独立的流量。
Requirement 2 (independence): If pod for building-2-deployment dies, I would like only building-2-deployment to be restarted and the other n-1 deployments to be not affected. 要求2(独立):如果建筑2部署的吊舱死亡,我希望仅重新启动建筑2部署而其他n-1部署不受影响。
Requirement 3 (kill then replace): If pod for building-2-deployment is unhealthy, I would like it to be killed then a new one created. 要求3(杀死后更换):如果用于建筑2部署的吊舱不健康,我希望将其杀死,然后创建一个新吊舱。 Not a replacement created, then the sick is killed. 如果没有创建替代品,那么病人就会被杀死。
When I update the image and issue a "kubectl apply -f building.yaml", I would like each deployment to be shut down then a new one started with the new SW. 当我更新映像并发布“ kubectl apply -f building.yaml”时,我希望关闭每个部署,然后以新的SW开始一个新的部署。 In other words, not create a second then kill the first. 换句话说,不要创造第二个然后杀死第一个。
Requirement 4 (yaml): This application is created and updated with a yaml file so that it's repeatable and archivable. 要求4(yaml):使用yaml文件创建和更新了此应用程序,以便其可重复和可归档。
Partial Solution: The following yaml creates routes (requirement 1) , operates each deployment independently (requirement 2) , but fails on to kill before starting a replacement (requirement 3) . 部分解决方案:以下yaml创建路由(要求1) ,独立运行每个部署(要求2) ,但在开始替换之前无法终止(要求3) 。
This partial solution is a little verbose as each deployment is replicated "n" time where only the "n" is changed. 这种局部解决方案有点冗长,因为每个部署都在“ n”次被复制的情况下被复制,其中仅更改了“ n”次。
I would appreciate a suggested to solve all 3 requirements. 我将建议解决所有3个要求。
apiVersion: v1
kind: Service
metadata:
name: building-1-service # http://building-1-service
spec:
ports:
- port: 80
targetPort: 80
type: NodePort
selector:
app: building-1-pod #matches name of pod being created by deployment
---
apiVersion: v1
kind: Service
metadata:
name: building-2-service # http://building-2-service
spec:
ports:
- port: 80
targetPort: 80
type: NodePort
selector:
app: building-2-pod #matches name of pod being created by deployment
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: building-1-deployment # name of the deployment
spec:
replicas: 1
selector:
matchLabels:
app: building-1-pod # matches name of pod being created
template:
metadata:
labels:
app: building-1-pod # name of pod, matches name in deployment and route "location /building_1/" in nginx.conf
spec:
containers:
- name: building-container # name of docker container
image: us.gcr.io//proj-12345/building:2018_03_19_19_45
resources:
limits:
cpu: "1"
requests:
cpu: "10m"
ports:
- containerPort: 80
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: building-2-deployment # name of the deployment
spec:
replicas: 1
selector:
matchLabels:
app: building-2-pod # matches name of pod being created
template:
metadata:
labels:
app: building-2-pod # name of pod, matches name in deployment and route "location /building_2/" in nginx.conf
spec:
containers:
- name: building-container # name of docker container
image: us.gcr.io//proj-12345/building:2018_03_19_19_45
resources:
limits:
cpu: "1"
requests:
cpu: "10m"
ports:
- containerPort: 80
You are in the luck. 你真幸运。 This is exactly what StatefulSets are for. 这正是StatefulSets的用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.