Te whakarite tukunga ki nga taiao k8 maha ma te whakamahi i te helmfile

Helmfile - takai mo potae, ka taea e koe te whakaahua i te maha o nga whakaputanga rei i te waahi kotahi, te whakarite i o raatau tūtohi mo te maha o nga taiao, me te whakarite hoki i te raupapa o te whakatakotoranga.

Ka taea e koe te panui mo te helmfile me nga tauira o tana whakamahinga i roto pānuimai и aratohu mahi pai.

Ka mohio tatou ki nga huarahi kore-marama hei whakaahua i nga whakaputanga i roto i te helmfile

Me kii kei a matou he kohinga tūtohi urungi (hei tauira, me kii ko nga pou me etahi tono whakamuri) me etahi taiao (he maha nga tautau kubernetes, he maha nga mokowā ingoa, he maha ranei o nga mea e rua). Ka tangohia e matou te konae, panuihia nga tuhinga ka timata ki te whakaahua i o maatau taiao me o maatau tuku:

    .
    ├── envs
    │   ├── devel
    │   │   └── values
    │   │       ├── backend.yaml
    │   │       └── postgres.yaml
    │   └── production
    │       └── values
    │           ├── backend.yaml
    │           └── postgres.yaml
    └── helmfile.yaml

helmfile.yaml

environments:
  devel:
  production:

releases:
  - name: postgres
    labels:
      app: postgres
    wait: true
    chart: stable/postgresql
    version: 8.4.0
    values:
      - envs/{{ .Environment.Name }}/values/postgres.yaml
  - name: backend
    labels:
      app: backend
    wait: true
    chart: private-helm-repo/backend
    version: 1.0.5
    needs:
      - postgres
    values:
      - envs/{{ .Environment.Name }}/values/backend.yaml

Ka mutu e 2 nga taiao: puhoi, production — kei ia tangata ona ake uara mo nga mahere tuku urungi. Ka tukuna atu e matou ki a raatau penei:

helmfile -n <namespace> -e <env> apply

Putanga rereke o nga tūtohi urungi i roto i nga taiao rereke

He aha mena ka hiahia tatou ki te whakaputa i nga momo momo momo tuara ki nga taiao rereke? Me pehea te whakarite i te putanga tuku? Ko nga uara taiao e waatea ana ma {{ .Values }}

helmfile.yaml

environments:
  devel:
+   values:
+   - charts:
+       versions:
+         backend: 1.1.0
  production:
+   values:
+   - charts:
+       versions:
+         backend: 1.0.5
...
  - name: backend
    labels:
      app: backend
    wait: true
    chart: private-helm-repo/backend
-   version: 1.0.5
+   version: {{ .Values.charts.versions.backend }}
...

He huinga tono rereke i roto i nga taiao rereke

He pai, engari me pehea mena kaore e hiahiatia production Hurihia nga poupou, na te mea e mohio ana matou kaore e tika kia panahia te paataka korero ki roto i nga k8 me te hoko he kahui poupou motuhake ta matou? Hei whakaoti i tenei raru kei a matou nga tapanga

helmfile -n <namespace> -e devel apply
helmfile -n <namespace> -e production -l app=backend apply

He pai tenei, engari ko ahau ake ka pai ake ahau ki te whakaahua i nga tono ka tukuna ki te taiao kaore i te whakamahi i nga tautohetohe whakarewatanga, engari i roto i te whakaahuatanga o nga taiao ake. Me aha? Ka taea e koe te whakanoho i nga whakaahuatanga tuku ki tetahi kōpaki motuhake, hangaia he rarangi o nga whakaputanga e tika ana i roto i te whakaahuatanga taiao me te "tangohia" nga putanga e tika ana, kaore e aro ki te toenga.

    .
    ├── envs
    │   ├── devel
    │   │   └── values
    │   │       ├── backend.yaml
    │   │       └── postgres.yaml
    │   └── production
    │       └── values
    │           ├── backend.yaml
    │           └── postgres.yaml
+   ├── releases
+   │   ├── backend.yaml
+   │   └── postgres.yaml
    └── helmfile.yaml

helmfile.yaml


  environments:
    devel:
      values:
      - charts:
          versions:
            backend: 1.1.0
      - apps:
        - postgres
        - backend

    production:
      values:
      - charts:
          versions:
            backend: 1.0.5
      - apps:
        - backend

- releases:
-    - name: postgres
-      labels:
-        app: postgres
-      wait: true
-      chart: stable/postgresql
-      version: 8.4.0
-      values:
-        - envs/{{ .Environment.Name }}/values/postgres.yaml
-    - name: backend
-      labels:
-        app: backend
-      wait: true
-      chart: private-helm-repo/backend
-     version: {{ .Values.charts.versions.backend }}
-     needs:
-       - postgres
-     values:
-       - envs/{{ .Environment.Name }}/values/backend.yaml
+ ---
+ bases:
+ {{- range .Values.apps }}
+   - releases/{{ . }}.yaml
+ {{- end }}

releases/postgres.yaml

releases:
  - name: postgres
    labels:
      app: postgres
    wait: true
    chart: stable/postgresql
    version: 8.4.0
    values:
      - envs/{{ .Environment.Name }}/values/postgres.yaml

releases/backend.yaml

releases:
  - name: backend
    labels:
      app: backend
    wait: true
    chart: private-helm-repo/backend
    version: {{ .Values.charts.versions.backend }}
    needs:
      - postgres
    values:
      - envs/{{ .Environment.Name }}/values/backend.yaml

Te tuhipoka

A, no te whakamahi bases: he mea tika ki te whakamahi i te yaml separator ---, kia taea ai e koe te tauira whakaputanga (me etahi atu waahanga, penei i te helmDefaults) me nga uara mai i nga taiao

I tenei keehi, ko te tukunga o te postgres e kore e whakauruhia ki te whakaahuatanga mo te whakaputa. Tino whakamarie!

Ko nga uara o te ao ka taea te whakakore mo nga tukunga

Ae ra, he mea pai ka taea e koe te whakarite uara mo nga tūtohi urungi mo ia taiao, engari he aha mena he maha nga taiao e whakaahuatia ana, a, e hiahia ana matou, hei tauira, kia rite ki te katoa. affinity, engari karekau matou e pai ki te whirihora ma te taunoa i roto i nga tūtohi ake, kei te rongoa i roto i nga keha.

I roto i tenei take, mo ia tukunga ka taea e matou te tohu i nga konae e 2 me nga uara: ko te tuatahi me nga uara taunoa, ka whakatau i nga uara o te tūtohi ake, me te tuarua me nga uara mo te taiao, ka huri ki te whakakore i te nga mea taunoa.

    .
    ├── envs
+   │   ├── default
+   │   │   └── values
+   │   │       ├── backend.yaml
+   │   │       └── postgres.yaml
    │   ├── devel
    │   │   └── values
    │   │       ├── backend.yaml
    │   │       └── postgres.yaml
    │   └── production
    │       └── values
    │           ├── backend.yaml
    │           └── postgres.yaml
    ├── releases
    │   ├── backend.yaml
    │   └── postgres.yaml
    └── helmfile.yaml

releases/backend.yaml

releases:
  - name: backend
    labels:
      app: backend
    wait: true
    chart: private-helm-repo/backend
    version: {{ .Values.charts.versions.backend }}
    needs:
      - postgres
    values:
+     - envs/default/values/backend.yaml
      - envs/{{ .Environment.Name }}/values/backend.yaml

envs/default/values/backend.yaml

affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 1
      podAffinityTerm:
        labelSelector:
          matchExpressions:
          - key: app.kubernetes.io/name
            operator: In
            values:
            - backend
        topologyKey: "kubernetes.io/hostname"

Te whakatau i nga uara o te ao mo nga tūtohi urungi o nga putanga katoa i te taumata taiao

Me kii ka hangaia e matou etahi whakaurunga maha i roto i nga putanga maha - ka taea e taatau te tautuhi a-ringa mo ia tūtohi hosts:, engari i roto i a maatau he rite tonu te rohe, no reira he aha e kore ai e tuu ki etahi taurangi o te ao me te whakakapi noa i tona uara ki nga tūtohi? Ki te mahi i tenei, ko nga konae me nga uara e hiahia ana matou ki te taapiri me whai toronga .gotmpl, kia mohio ai helmfile me whakahaere ma te miihini tauira.

    .
    ├── envs
    │   ├── default
    │   │   └── values
-   │   │       ├── backend.yaml
-   │   │       ├── postgres.yaml
+   │   │       ├── backend.yaml.gotmpl
+   │   │       └── postgres.yaml.gotmpl
    │   ├── devel
    │   │   └── values
    │   │       ├── backend.yaml
    │   │       └── postgres.yaml
    │   └── production
    │       └── values
    │           ├── backend.yaml
    │           └── postgres.yaml
    ├── releases
    │   ├── backend.yaml
    │   └── postgres.yaml
    └── helmfile.yaml

helmfile.yaml

  environments:
    devel:
      values:
      - charts:
          versions:
            backend: 1.1.0
      - apps:
        - postgres
        - backend
+     - global:
+         ingressDomain: k8s.devel.domain

    production:
      values:
      - charts:
          versions:
            backend: 1.0.5
      - apps:
        - backend
+     - global:
+         ingressDomain: production.domain
  ---
  bases:
  {{- range .Values.apps }}
    - releases/{{ . }}.yaml
  {{- end }}

envs/default/values/backend.yaml.gotmpl

ingress:
  enabled: true
  paths:
    - /api
  hosts:
    - {{ .Values.global.ingressDomain }}

envs/default/values/postgres.yaml.gotmpl

ingress:
  enabled: true
  paths:
    - /
  hosts:
    - postgres.{{ .Values.global.ingressDomain }}

Te tuhipoka

Ma te maarama, ko te whakaurunga ki roto i te tūtohi postgres he mea tino pohehe, no reira ka tukuna tenei tuhinga hei tauira porowhita i roto i te korehau kia kore ai e whakauruhia he tuku hou ki roto i te tuhinga mo te whakamaarama i te whakaurunga.

Te whakakapi i nga mea ngaro mai i nga uara taiao

Ma te whakataurite ki te tauira i runga ake nei, ka taea e koe te whakakapi i nga mea whakamunatia ma te whakamahi nga mea ngaro urungi tikanga. Engari ki te hanga i a maatau ake konae ngaro mo ia tukunga, ka taea e taatau te tautuhi i nga uara whakamunatia mo te tūtohi, ka taea e taatau te tautuhi i roto i te tukunga default.yaml.gotmpl nga uara ka tangohia mai i nga taurangi kua tautuhia i te taumata taiao. A ko nga uara e kore e tika kia huna mai i tetahi ka taea te tautuhi ano i nga uara tuku i roto i tetahi taiao motuhake.

    .
    ├── envs
    │   ├── default
    │   │   └── values
    │   │       ├── backend.yaml
    │   │       └── postgres.yaml
    │   ├── devel
    │   │   ├── values
    │   │   │   ├── backend.yaml
    │   │   │   └── postgres.yaml
+   │   │   └── secrets.yaml
    │   └── production
    │       ├── values
    │       │   ├── backend.yaml
    │       │   └── postgres.yaml
+   │       └── secrets.yaml
    ├── releases
    │   ├── backend.yaml
    │   └── postgres.yaml
    └── helmfile.yaml

helmfile.yaml

  environments:
    devel:
      values:
      - charts:
          versions:
            backend: 1.1.0
      - apps:
        - postgres
        - backend
      - global:
          ingressDomain: k8s.devel.domain
+     secrets:
+       - envs/devel/secrets.yaml

    production:
      values:
      - charts:
          versions:
            backend: 1.0.5
      - apps:
        - backend
      - global:
          ingressDomain: production.domain
+     secrets:
+       - envs/production/secrets.yaml
  ---
  bases:
  {{- range .Values.apps }}
    - releases/{{ . }}.yaml
  {{- end }}

envs/devel/secrets.yaml

secrets:
    elastic:
        password: ENC[AES256_GCM,data:hjCB,iv:Z1P6/6xBJgJoKLJ0UUVfqZ80o4L84jvZfM+uH9gBelc=,tag:dGqQlCZnLdRAGoJSj63rBQ==,type:int]
...

envs/production/secrets.yaml

secrets:
    elastic:
        password: ENC[AES256_GCM,data:ZB/VpTFk8f0=,iv:EA//oT1Cb5wNFigTDOz3nA80qD9UwTjK5cpUwLnEXjs=,tag:hMdIUaqLRA8zuFBd82bz6A==,type:str]
...

envs/default/values/backend.yaml.gotmpl

elasticsearch:
  host: elasticsearch
  port: 9200
  password: {{ .Values | getOrNil "secrets.elastic.password" | default "password" }}

envs/devel/values/backend.yaml

elasticsearch:
  host: elastic-0.devel.domain

envs/production/values/backend.yaml

elasticsearch:
  host: elastic-0.production.domain

Te tuhipoka

I te ara, getOrNil - he mahi motuhake mo nga tauira haere i te helmfile, ahakoa .Values.secrets e kore e noho, e kore e maka he hapa, engari ka whakaaetia te hua ma te whakamahi i te mahi default whakakapi uara taunoa

mutunga

Ko nga mea i whakaahuahia he ahua tino marama, engari ko nga korero mo te whakamaarama ngawari mo te tuku ki nga waahi maha ma te whakamahi i te helmfile he iti rawa, a he pai ki a au te IaC (Infrastructure-as-Code) me te hiahia kia marama te whakamaarama mo te ahuatanga tuku.

Hei mutunga, e hiahia ana ahau ki te taapiri ko nga taurangi mo te taiao taunoa ka taea te whakataurite ki nga taurangi taiao o te OS o tetahi kaikawe mai i reira ka whakarewahia te tukunga, na reira ka whiwhi taiao hihiri.

helmfile.yaml

environments:
  default:
    values:
    - global:
        clusterDomain: {{ env "CLUSTER_DOMAIN" | default "cluster.local" }}
        ingressDomain: {{ env "INGRESS_DOMAIN" }}

Source: will.com

Tāpiri i te kōrero