简体   繁体   English

使用不同的值创建相同的 pod

[英]Create an identical pod using different values

I currently have an app deployed on k8s using Skaffold.我目前使用 Skaffold 在 k8s 上部署了一个应用程序。 Using Helm I have defined the main deployment.yaml manifest as a template and used a values.yaml to insert other values into that deployment template.使用 Helm,我将主要的deployment.yaml清单定义为模板,并使用values.yaml将其他值插入到该部署模板中。

What I would like to do is have 2 deployments of the same app using different values from the values.yaml file.我想做的是使用values.yaml文件中的不同值对同一应用程序进行 2 次部署。 So essentially 2 pods running the same application aside from the different values provided, for instance a my-app-blue pod and my-app-green pod.因此,除了提供的不同值之外,基本上 2 个 pod 运行相同的应用程序,例如my-app-blue pod 和my-app-green pod。 Is there anyway that I can do this without having to use a whole new deployment.yaml file?无论如何我可以做到这一点而不必使用全新的deployment.yaml文件? Sorry for any ambiguity I'm new to K8s, Helm, and Skaffold.抱歉,我是 K8s、Helm 和 Skaffold 的新手。

deployment.yaml部署.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
   namespace: {{ .Values.namespace }}
   name: {{ .Values.name }}
spec:
   replicas: {{ .Values.blue-deployment.replicas }}
   template:
      spec:
         containers:
            -  name: {{ .Values.blue-deployment.name }}
               image: {{ .Values.blue-deployment.image }}

values.yaml值.yaml

namespace: my-app
name: app

blue-deployment:
   name: blue
   image: my-image
   replicas: 1
   env:
      - name: COLOR
        value: 'blue'

green-deployment:
   name: green
   image: my-image
   replicas: 1
   env:
      - name: COLOR
        value: 'green'

skaffold.yaml脚手架.yaml

apiVersion: skaffold/v2beta
kind: Config
build:
   artifacts:
      - image: blue-deployment
        context: './'
deploy:
   - name: my-application
     chartPath: kubernetes
     valuesFiles:
        - kubernetes/values.yaml
     namespace: my-app

directory structure:目录结构:

myApp/
kubernetes/
   templates/
      myApp/
         deployment.yaml
   values.yaml
skaffold.yaml
Dockerfile   

Just use a loop.只需使用一个循环。 helm range 掌舵范围

values.yaml值.yaml

namespace: my-app
name: app

deps:
  - name: blue
    image: my-image
    replicas: 1
    env:
      - name: COLOR
        value: 'blue'

  - name: green
    image: my-image
    replicas: 1
    env:
      - name: COLOR
        value: 'green'

deployment.yaml部署.yaml

{{- $i, $v := range .Values.deps}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
   namespace: {{ .Values.namespace }}
   name: {{ $v.name }}
spec:
   replicas: {{ $v.replicas }}
   template:
      spec:
         containers:
            -  name: {{ $v.name }}
               image: {{ $v.image }}
{{- end }}

output输出

---
apiVersion: apps/v1
kind: Deployment
metadata:
   namespace: my-app
   name: blue
spec:
   replicas: 1
   template:
      spec:
         containers:
            -  name: blue
               image: my-image
---
apiVersion: apps/v1
kind: Deployment
metadata:
   namespace: my-app
   name: green
spec:
   replicas: 1
   template:
      spec:
         containers:
            -  name: green
               image: my-image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM