要求1(路线): 我需要能够路由到" n"独立的Kubernetes部署。如:
每栋建筑都接收独立于其他建筑物的交通。
要求2(独立): 如果用于构建2部署的pod死机,我希望只重新启动构建2部署,并且不会影响其他n-1部署。
要求3(杀死然后替换): 如果用于构建2部署的pod不健康,我希望它被杀死然后创建一个新的。没有创建替代品,病人就会被杀死。
当我更新图像并发出" kubectl apply -f building.yaml"时,我希望关闭每个部署,然后使用新SW启动新部署。换句话说,不要创建第二个然后杀死第一个。
要求4(yaml):此应用程序是使用yaml文件创建和更新的,因此它可以重复和存档。
部分解决方案: 以下yaml创建路径(要求1),独立操作每个部署(要求2),但在开始替换之前未能杀死(要求3)< / strong>即可。
这个部分解决方案有点冗长,因为每个部署都被复制了&#34; n&#34;时间只有&#34; n&#34;改变了。
我很感激建议解决所有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