Kubernetes Helm 3 Sheet: Release & Rollback

๐Ÿ’ก Kubernetes Helm 3 Sheet: Release & Rollback โ€” Executive Summary

Technical architectural analysis, practical configuration manifests, and deployment instructions for Kubernetes Helm 3 Sheet: Release & Rollback.

Installation

bash
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

Exec

completion
html
echo "source <(helm completion bash)" >> ~/.bashrc
source ~/.bashrc
search
bash
# artifacthub.io์—์„œ ์ฐจํŠธ ๊ฒ€์ƒ‰
helm search hub {{ ๊ฒ€์ƒ‰์–ด }}

# repository๋ช…์œผ๋กœ ์ฐจํŠธ ๊ฒ€์ƒ‰
helm search repo {{ ๊ฒ€์ƒ‰์–ด }}

repository: chart repository like Docker HUB
artifacthub.io:

bash
# ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ถ”๊ฐ€
helm repo add [NAME] [URL] [flags]
# helm repo add bitnami https://charts.bitnami.com/bitnami

# values show
helm show values $repo/$chart
helm show readme $repo/$chart
helm show chart $repo/$chart
helm show crds $repo/$chart
helm template .
helm show values kiali/kiali-server --version=v1.82.0 > values.origin

# ์ธ์Šคํ†จ
helm install my-release bitnami/<chart>

# values.yaml ๊ฒฝ๋กœ์—์„œ
helm install ${appname} . -n ${namespace}

# ์—…๊ทธ๋ ˆ์ด๋“œ
# values.yaml ๊ฒฝ๋กœ์—์„œ
helm upgrade ${appname} . -n ${namespace}

# ํŒจํ‚ค์ง€ ํŒŒ์ผ ์ƒ์„ฑ
helm package .

# ํŒจํ‚ค์ง€ ํŒŒ์ผ helm repository์— push
helm push $package.tgz oci://$myrepository/$project
repo
bash
#index.yaml ํ˜„์žฌ ๊ฒฝ๋กœ ๊ธฐ์ค€์œผ๋กœ ์ƒ์„ฑ (helm repository index)
helm repo index .

#helm repository ๋“ฑ๋ก
helm repo add $repository $repositoryURL
list


helm list attributes

sql
helm list --help


This command lists all of the releases for a specified namespace (uses current namespace context if namespace not specified).

By default, it lists only releases that are deployed or failed. Flags like
'--uninstalled' and '--all' will alter this behavior. Such flags can be combined:
'--uninstalled --failed'.

By default, items are sorted alphabetically. Use the '-d' flag to sort by
release date.

If the --filter flag is provided, it will be treated as a filter. Filters are
regular expressions (Perl compatible) that are applied to the list of releases.
Only items that match the filter will be returned.

    $ helm list --filter 'ara[a-z]+'
    NAME                UPDATED                                  CHART
    maudlin-arachnid    2020-06-18 14:17:46.125134977 +0000 UTC  alpine-0.1.0

If no results are found, 'helm list' will exit 0, but with no output (or in
the case of no '-q' flag, only headers).

By default, up to 256 items may be returned. To limit this, use the '--max' flag.
Setting '--max' to 0 will not return all results. Rather, it will return the
server's default, which may be much higher than 256. Pairing the '--max'
flag with the '--offset' flag allows you to page through results.

Usage:
  helm list [flags]

Aliases:
  list, ls

Flags:
  -a, --all                  show all releases without any filter applied
  -A, --all-namespaces       list releases across all namespaces
  -d, --date                 sort by release date
      --deployed             show deployed releases. If no other is specified, this will be automatically enabled
      --failed               show failed releases
  -f, --filter string        a regular expression (Perl compatible). Any releases that match the expression will be included in the results
  -h, --help                 help for list
  -m, --max int              maximum number of releases to fetch (default 256)
      --offset int           next release index in the list, used to offset from start value
  -o, --output format        prints the output in the specified format. Allowed values: table, json, yaml (default table)
      --pending              show pending releases
  -r, --reverse              reverse the sort order
  -l, --selector string      Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Works only for secret(default) and configmap storage backends.
  -q, --short                output short (quiet) listing format
      --superseded           show superseded releases
      --time-format string   format time using golang time formatter. Example: --time-format "2006-01-02 15:04:05Z0700"
      --uninstalled          show uninstalled releases (if 'helm uninstall --keep-history' was used)
      --uninstalling         show releases that are currently being uninstalled

Global Flags:
      --debug                       enable verbose output
      --kube-apiserver string       the address and the port for the Kubernetes API server
      --kube-as-group stringArray   group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --kube-as-user string         username to impersonate for the operation
      --kube-ca-file string         the certificate authority file for the Kubernetes API server connection
      --kube-context string         name of the kubeconfig context to use
      --kube-token string           bearer token used for authentication
      --kubeconfig string           path to the kubeconfig file
  -n, --namespace string            namespace scope for this request
      --registry-config string      path to the registry config file (default "/root/.config/helm/registry/config.json")
      --repository-cache string     path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
      --repository-config string    path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
pull
bash
# dir๋กœ ๋‹ค์šด๋กœ๋“œ
helm pull ${repo}/${appname} --untar --version=${chart-version}
install
bash
# values.yaml ๊ฒฝ๋กœ ๋‚ด์—์„œ
helm install -n ${namespace} ${appname} .
helm install -n ${namespace} ${appname} . --create-namespace
# ๋ฆฌํฌ์—์„œ ๊ฐ€์ ธ์˜ค๊ธฐ
helm install -n ${namespace} ${appname} ${repo}/${appname} --set ${flags_for_overwrite}

# map value set
#cat values.yaml | yq -o props
--set foo.bar={ foo: bar }
update
bash
# values.yaml ๊ฒฝ๋กœ ๋‚ด์—์„œ
helm update -n ${namespace} ${appname} .
uninstall
bash
helm uninstall -n ${namespace} ${appname}
status
bash
# helm release์ •๋ณด, ์„ค์น˜ Description ํ™•์ธ
helm status -n ${namespace} ${appname}
get
bash
# deploy๋œ ๋ชจ๋“  template metadata ํ™•์ธ ( k8s-manifests )
helm get all -n ${namespace} ${appname}

OCI-based registry

In fact, the helm registry provided by Harbor is an OCI-based registry. This registry has a slightly different personality from the general helm chart registry. First of all, OCI-based registry support is officially available starting with Helm version 3.8, and it is said that OCI worked differently in Helm in versions prior to 3.8. So, to use the OCI-based registry normally, you must check whether the helm version is 3.8 or higher.

bash
helm registry login $registry
helm registry logout $registry
helm push $package.tgz oci://$registry
helm pull oci://$registry
helm show $target oci://$registry
helm template $target oci://$registry
helm install $releasename -n $ns oci://$registry
helm upgrade $releasename -n $ns oci://$registry

Create Helm Chart

bash
helm create $chartname
Tips for writing values
Tips for finding necessary values when changing chart structure
bash
# ๊ธฐ์กด values.yaml์„ ๋ฐฑ์—…ํ•˜๊ณ , ๋นˆ values.yaml์„ ์ƒ์„ฑํ•œ๋‹ค
mv values.yaml values-backup.yaml
> values.yaml

# ํ…œํ”Œ๋ฆฟ์„ ํ…Œ์ŠคํŠธํ•ด๋ณธ๋‹ค.
helm template mychart .
Error: template: cmp-common-si/templates/spring-cloud-vault.yaml:4:18: executing "cmp-common-si/templates/spring-cloud-vault.yaml" at <.Values.global.config.namePrefix>: nil pointer evaluating interface {}.config

Use --debug flag to render out invalid YAML

# yq๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐฑ์—…์—์„œ ๊ฐ€์ ธ์˜ด
cat values-backup.yaml | yq -oprops | grep 'global.config.namePrefix' | yq -pprops >> values.yaml
bjw-s-labs Guideline
References and Guidelines (NOTE)

Currently the most widely used repository in the Kubernetes community (especially when building GitOps-based infrastructures) to eliminate code repetition.

  • Overview: Typical web apps, API servers, backends, etc. have more than 90% of the same Deployment, Service, Ingress, and PVC structures. This repository was created with the philosophy, โ€œInstead of creating a new chart every time, just inject different values.yaml into one universal chart.โ€
  • How it works: You do not write any Helm Chart templates (YAML files). After importing this app-template repository, simply declare the container image, port, ingress, and volume structure in values.yaml and the Kubernetes resources will be automatically rendered.
  • Repository address: https://bjw-s-labs.github.io/helm-charts
1. Create a new chart directory structure

First, create a folder for the new chart. (Example: my-custom-app)

bash
helm create my-custom-app
cd my-custom-app
rm -rf templates/*
References and Guidelines (NOTE)

Caution: Unlike the typical Helm structure, we do not create a templates folder or write YAML such as Deployment, Service, etc. directly in it.

2. Write Chart.yaml (define dependencies)

The most important thing in Chart.yaml is to register the bjw-s-labs repository as dependencies and fully import that chart’s functionality into my chart.

yaml
apiVersion: v2
name: my-custom-app
description: # input this
type: application
version: 1.0.0
appVersion: "1.0.0"

dependencies:
  - name: common
    version: 5.0.1
    repository: https://bjw-s-labs.github.io/helm-charts/

or Local Repository

yaml
dependencies:
  - name: common
    version: 5.0.1
    repository: "file://./charts/common"
bash
helm repo add bjw-s https://bjw-s-labs.github.io/helm-charts/
cd charts
helm pull bjw-s/common --untar
3. Write values.yaml (application specification)

App Template

yaml
controllers:
  main:
    strategy: Recreate

    containers:
      main:
        image:
          repository: vaultwarden/server
          tag: 1.25.2

        env:
          DATA_FOLDER: "config"

service:
  main:
    controller: main
    ports:
      http:
        port: 80
      websocket:
        enabled: true
        port: 3012

ingress:
  main:
    hosts:
      - host: vaultwarden.example.com
        paths:
          - path: /
            pathType: Prefix
            service:
              identifier: main
              port: http

persistence:
  config:
    type: persistentVolumeClaim
    accessMode: ReadWriteOnce
    size: 1Gi
    globalMounts:
      - path: /config
4. Build dependencies and verify locally (CLI workflow)

Once the chart structure has been created, proceed with verification in the terminal according to the guidelines below.

yaml
#Step 1: ์˜์กด์„ฑ ์ฐจํŠธ ๋‹ค์šด๋กœ๋“œ
helm dependency update ./my-custom-app

#Step 2: ํ…œํ”Œ๋ฆฟ ์ •์  ๋ถ„์„ (Lint)
helm lint ./my-custom-app

#Step 3: ์ตœ์ข… ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค YAML ๋ Œ๋”๋ง ํ™•์ธ (Dry-run / Template)
helm template my-release ./my-custom-app
๐Ÿ’ก Official Guidelines Key Summary
  1. Prohibit creation of templates: Leave the templates/ directory empty. All resource types are determined solely by structural declarations in values.yaml.
  2. Controller-centric structure: Based on the controllers..containers. structure, multi-container (Sidecar, etc.) patterns can also be easily extended within values.yaml.
  3. Be careful about updates: When major version updates (e.g. v1 -> v2 -> v3), the values.yaml schema structure tends to change significantly, so when declaring dependencies, you must keep the version fixed (v3.x.x) to keep the infrastructure stable.

features

Bitnami Chart Download / Control
bash
# repo ๋“ฑ๋ก
helm repo add bitnami https://charts.bitnami.com/bitnami

# ์ฐจํŠธ ์ „์ฒด ๋ฆฌ์ŠคํŠธ
helm search repo bitnami

# ์ฐจํŠธ ๋ฒ„์ „๋ฆฌ์ŠคํŠธ
helm search repo bitnami/grafana -l

# ์ฐจํŠธ ๋‹ค์šด๋กœ๋“œ
helm pull bitnami/grafana --untar --version=8.2.17 #Chart-version
chart push for my repository OCI
bash
docker login $myrepository
helm push $(helm package . | grep -o '/.*') oci://$myrepository/$project
Deploy to helm repository (1 depth)
bash
helm package */.
helm repo index .
Generate Default value
bash
helm show values ${repo}/${chart} > values.origin.yaml
Get Overwritten Values
bash
#helm repo list
#...
repo= #Set your repo `Name` -- ์‚ฌ์šฉ์ž๊ฐ€ ๋“ฑ๋กํ•œ repo Name์€ ์ผ๋ฐ˜ํ™”ํ•  ์ˆ˜ ์—†์Œ.
sdiff -s \
 <(helm show values ${repo}/$(cat Chart.yaml | yq '.name') \
   --version=$(cat Chart.yaml | yq '.version') | yq -oprops) \
 <(cat ./values.yaml | yq -oprops)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *