首页 文章

kubernetes“n”独立的 beans 荚,身份1到n

提问于
浏览
0

Requirement 1 (routes): 我需要能够路由到"n"独立的Kubernetes部署 . 如:

每栋建筑都接收独立于其他建筑物的交通 .

Requirement 2 (independence): 如果用于构建2部署的pod死机,我希望仅重新启动构建2部署,并且不影响其他n-1部署 .

Requirement 3 (kill then replace): 如果用于构建2部署的pod不 Health ,我希望它被杀死然后创建一个新的 . 没有替代创建,然后病人被杀死 .

当我更新图像并发出“kubectl apply -f building.yaml”时,我希望关闭每个部署,然后使用新SW启动新部署 . 换句话说,不创建第二个然后杀死第一个 .

Requirement 4 (yaml): 使用yaml文件创建和更新此应用程序,以便它可重复和可存档 .

  • kubectl create -f building.yaml

  • kubectl apply -f building.yaml

Partial Solution: 以下yaml创建路由 (requirement 1) ,独立操作每个部署 (requirement 2) ,但在开始替换 (requirement 3) 之前无法启动 .

这个部分解决方案有点冗长,因为每个部署都复制了“n”时间,其中只有“n”被更改 .

我很感激建议解决所有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

1 回答

  • 1

    你很幸运 . 这正是StatefulSets的用途 .

相关问题