github.com/koderover/helm@v2.17.0+incompatible/docs/using_helm.md (about) 1 # Using Helm 2 3 This guide explains the basics of using Helm (and Tiller) to manage 4 packages on your Kubernetes cluster. It assumes that you have already 5 [installed](install.md) the Helm client and the Tiller server (typically by `helm 6 init`). 7 8 If you are simply interested in running a few quick commands, you may 9 wish to begin with the [Quickstart Guide](quickstart.md). This chapter 10 covers the particulars of Helm commands, and explains how to use Helm. 11 12 ## Three Big Concepts 13 14 A *Chart* is a Helm package. It contains all of the resource definitions 15 necessary to run an application, tool, or service inside of a Kubernetes 16 cluster. Think of it like the Kubernetes equivalent of a Homebrew formula, 17 an Apt dpkg, or a Yum RPM file. 18 19 A *Repository* is the place where charts can be collected and shared. 20 It's like Perl's [CPAN archive](https://www.cpan.org) or the 21 [Fedora Package Database](https://apps.fedoraproject.org/packages/s/pkgdb), but 22 for Kubernetes packages. 23 24 A *Release* is an instance of a chart running in a Kubernetes cluster. 25 One chart can often be installed many times into the same cluster. And 26 each time it is installed, a new _release_ is created. Consider a MySQL 27 chart. If you want two databases running in your cluster, you can 28 install that chart twice. Each one will have its own _release_, which 29 will in turn have its own _release name_. 30 31 With these concepts in mind, we can now explain Helm like this: 32 33 Helm installs _charts_ into Kubernetes, creating a new _release_ for 34 each installation. And to find new charts, you can search Helm chart 35 _repositories_. 36 37 ## 'helm search': Finding Charts 38 39 When you first install Helm, it is preconfigured to talk to the official 40 Kubernetes charts repository. This repository contains a number of 41 carefully curated and maintained charts. This chart repository is named 42 `stable` by default. 43 44 You can see which charts are available by running `helm search`: 45 46 ```console 47 $ helm search 48 NAME VERSION DESCRIPTION 49 stable/drupal 0.3.2 One of the most versatile open source content m... 50 stable/jenkins 0.1.0 A Jenkins Helm chart for Kubernetes. 51 stable/mariadb 0.5.1 Chart for MariaDB 52 stable/mysql 0.1.0 Chart for MySQL 53 ... 54 ``` 55 56 With no filter, `helm search` shows you all of the available charts. You 57 can narrow down your results by searching with a filter: 58 59 ```console 60 $ helm search mysql 61 NAME VERSION DESCRIPTION 62 stable/mysql 0.1.0 Chart for MySQL 63 stable/mariadb 0.5.1 Chart for MariaDB 64 ``` 65 66 Now you will only see the results that match your filter. 67 68 Why is 69 `mariadb` in the list? Because its package description relates it to 70 MySQL. We can use `helm inspect chart` to see this: 71 72 ```console 73 $ helm inspect stable/mariadb 74 apiVersion: v1 75 appVersion: 10.3.22 76 deprecated: true 77 description: DEPRECATED Fast, reliable, scalable, and easy to use open-source relational database system. MariaDB Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software. Highly available MariaDB cluster. 78 engine: gotpl 79 home: https://mariadb.org 80 icon: https://bitnami.com/assets/stacks/mariadb/img/mariadb-stack-220x234.png 81 keywords: 82 - mariadb 83 - mysql 84 - database 85 - sql 86 - prometheus 87 name: mariadb 88 sources: 89 - https://github.com/bitnami/bitnami-docker-mariadb 90 - https://github.com/prometheus/mysqld_exporter 91 version: 7.3.14 92 ... 93 ``` 94 95 Sometimes there will be a development version of a chart available. Compare 96 these excerpts for the spinnaker chart's default vs development versions: 97 98 ```console 99 $ helm inspect stable/spinnaker 100 apiVersion: v1 101 appVersion: 1.16.2 102 description: Open source, multi-cloud continuous delivery platform for releasing software changes with high velocity and confidence. 103 home: http://spinnaker.io/ 104 icon: https://pbs.twimg.com/profile_images/669205226994319362/O7OjwPrh_400x400.png 105 maintainers: 106 - email: viglesias@google.com 107 name: viglesiasce 108 - email: ezimanyi@google.com 109 name: ezimanyi 110 - email: hello@dwardu.com 111 name: dwardu89 112 - email: username.taken@gmail.com 113 name: paulczar 114 name: spinnaker 115 sources: 116 - https://github.com/spinnaker 117 - https://github.com/viglesiasce/images 118 version: 1.23.3 119 ... 120 ``` 121 122 ```console 123 $ helm inspect stable/spinnaker --devel 124 125 apiVersion: v1 126 appVersion: 1.16.2 127 description: Open source, multi-cloud continuous delivery platform for releasing software changes with high velocity and confidence. 128 home: http://spinnaker.io/ 129 icon: https://pbs.twimg.com/profile_images/669205226994319362/O7OjwPrh_400x400.png 130 maintainers: 131 - email: viglesias@google.com 132 name: viglesiasce 133 - email: ezimanyi@google.com 134 name: ezimanyi 135 - email: hello@dwardu.com 136 name: dwardu89 137 - email: username.taken@gmail.com 138 name: paulczar 139 name: spinnaker 140 sources: 141 - https://github.com/spinnaker 142 - https://github.com/viglesiasce/images 143 version: 2.0.0-rc5 144 ... 145 ``` 146 147 Search is a good way to find available packages. Once you have found a 148 package you want to install, you can use `helm install` to install it. 149 150 ## 'helm install': Installing a Package 151 152 To install a new package, use the `helm install` command. At its 153 simplest, it takes only one argument: The name of the chart. 154 155 ```console 156 $ helm install stable/mariadb 157 Fetched stable/mariadb-0.3.0 to /Users/mattbutcher/Code/Go/src/k8s.io/helm/mariadb-0.3.0.tgz 158 NAME: happy-panda 159 LAST DEPLOYED: Wed Sep 28 12:32:28 2016 160 NAMESPACE: default 161 STATUS: DEPLOYED 162 163 Resources: 164 ==> extensions/Deployment 165 NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 166 happy-panda-mariadb 1 0 0 0 1s 167 168 ==> v1/Secret 169 NAME TYPE DATA AGE 170 happy-panda-mariadb Opaque 2 1s 171 172 ==> v1/Service 173 NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 174 happy-panda-mariadb 10.0.0.70 <none> 3306/TCP 1s 175 176 177 Notes: 178 MariaDB can be accessed via port 3306 on the following DNS name from within your cluster: 179 happy-panda-mariadb.default.svc.cluster.local 180 181 To connect to your database run the following command: 182 183 kubectl run happy-panda-mariadb-client --rm --tty -i --image bitnami/mariadb --command -- mysql -h happy-panda-mariadb 184 ``` 185 186 Now the `mariadb` chart is installed. Note that installing a chart 187 creates a new _release_ object. The release above is named 188 `happy-panda`. (If you want to use your own release name, simply use the 189 `--name` flag on `helm install`.) 190 191 During installation, the `helm` client will print useful information 192 about which resources were created, what the state of the release is, 193 and also whether there are additional configuration steps you can or 194 should take. 195 196 Helm does not wait until all of the resources are running before it 197 exits. Many charts require Docker images that are over 600M in size, and 198 may take a long time to install into the cluster. 199 200 To keep track of a release's state, or to re-read configuration 201 information, you can use `helm status`: 202 203 ```console 204 $ helm status happy-panda 205 Last Deployed: Wed Sep 28 12:32:28 2016 206 Namespace: default 207 Status: DEPLOYED 208 209 Resources: 210 ==> v1/Service 211 NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 212 happy-panda-mariadb 10.0.0.70 <none> 3306/TCP 4m 213 214 ==> extensions/Deployment 215 NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 216 happy-panda-mariadb 1 1 1 1 4m 217 218 ==> v1/Secret 219 NAME TYPE DATA AGE 220 happy-panda-mariadb Opaque 2 4m 221 222 223 Notes: 224 MariaDB can be accessed via port 3306 on the following DNS name from within your cluster: 225 happy-panda-mariadb.default.svc.cluster.local 226 227 To connect to your database run the following command: 228 229 kubectl run happy-panda-mariadb-client --rm --tty -i --image bitnami/mariadb --command -- mysql -h happy-panda-mariadb 230 ``` 231 232 The above shows the current state of your release. 233 234 ### Customizing the Chart Before Installing 235 236 Installing the way we have here will only use the default configuration 237 options for this chart. Many times, you will want to customize the chart 238 to use your preferred configuration. 239 240 To see what options are configurable on a chart, use `helm inspect 241 values`: 242 243 ```console 244 helm inspect values stable/mariadb 245 Fetched stable/mariadb-0.3.0.tgz to /Users/mattbutcher/Code/Go/src/k8s.io/helm/mariadb-0.3.0.tgz 246 ## Bitnami MariaDB image version 247 ## ref: https://hub.docker.com/r/bitnami/mariadb/tags/ 248 ## 249 ## Default: none 250 imageTag: 10.1.14-r3 251 252 ## Specify a imagePullPolicy 253 ## Default to 'Always' if imageTag is 'latest', else set to 'IfNotPresent' 254 ## ref: https://kubernetes.io/docs/user-guide/images/#pre-pulling-images 255 ## 256 # imagePullPolicy: 257 258 ## Specify password for root user 259 ## ref: https://github.com/bitnami/bitnami-docker-mariadb/blob/master/README.md#setting-the-root-password-on-first-run 260 ## 261 # mariadbRootPassword: 262 263 ## Create a database user 264 ## ref: https://github.com/bitnami/bitnami-docker-mariadb/blob/master/README.md#creating-a-database-user-on-first-run 265 ## 266 # mariadbUser: 267 # mariadbPassword: 268 269 ## Create a database 270 ## ref: https://github.com/bitnami/bitnami-docker-mariadb/blob/master/README.md#creating-a-database-on-first-run 271 ## 272 # mariadbDatabase: 273 ``` 274 275 You can then override any of these settings in a YAML formatted file, 276 and then pass that file during installation. 277 278 ```console 279 $ cat << EOF > config.yaml 280 mariadbUser: user0 281 mariadbDatabase: user0db 282 EOF 283 $ helm install -f config.yaml stable/mariadb 284 ``` 285 286 The above will create a default MariaDB user with the name `user0`, and 287 grant this user access to a newly created `user0db` database, but will 288 accept all the rest of the defaults for that chart. 289 290 There are two ways to pass configuration data during install: 291 292 - `--values` (or `-f`): Specify a YAML file with overrides. This can be specified multiple times 293 and the rightmost file will take precedence 294 - `--set` (and its variants `--set-string` and `--set-file`): Specify overrides on the command line. 295 296 If both are used, `--set` values are merged into `--values` with higher precedence. 297 Overrides specified with `--set` are persisted in a configmap. Values that have been 298 `--set` can be viewed for a given release with `helm get values <release-name>`. 299 Values that have been `--set` can be cleared by running `helm upgrade` with `--reset-values` 300 specified. 301 302 #### The Format and Limitations of `--set` 303 304 The `--set` option takes zero or more name/value pairs. At its simplest, it is 305 used like this: `--set name=value`. The YAML equivalent of that is: 306 307 ```yaml 308 name: value 309 ``` 310 311 Multiple values are separated by `,` characters. So `--set a=b,c=d` becomes: 312 313 ```yaml 314 a: b 315 c: d 316 ``` 317 318 More complex expressions are supported. For example, `--set outer.inner=value` is 319 translated into this: 320 ```yaml 321 outer: 322 inner: value 323 ``` 324 325 Lists can be expressed by enclosing values in `{` and `}`. For example, 326 `--set name={a, b, c}` translates to: 327 328 ```yaml 329 name: 330 - a 331 - b 332 - c 333 ``` 334 335 As of Helm 2.5.0, it is possible to access list items using an array index syntax. 336 For example, `--set servers[0].port=80` becomes: 337 338 ```yaml 339 servers: 340 - port: 80 341 ``` 342 343 Multiple values can be set this way. The line `--set servers[0].port=80,servers[0].host=example` becomes: 344 345 ```yaml 346 servers: 347 - port: 80 348 host: example 349 ``` 350 351 Sometimes you need to use special characters in your `--set` lines. You can use 352 a backslash to escape the characters; `--set name="value1\,value2"` will become: 353 354 ```yaml 355 name: "value1,value2" 356 ``` 357 358 Similarly, you can escape dot sequences as well, which may come in handy when charts use the 359 `toYaml` function to parse annotations, labels and node selectors. The syntax for 360 `--set nodeSelector."kubernetes\.io/role"=master` becomes: 361 362 ```yaml 363 nodeSelector: 364 kubernetes.io/role: master 365 ``` 366 367 Deeply nested data structures can be difficult to express using `--set`. Chart 368 designers are encouraged to consider the `--set` usage when designing the format 369 of a `values.yaml` file. 370 371 Helm will cast certain values specified with `--set` to integers. 372 For example, `--set foo=true` results Helm to cast `true` into an int64 value. 373 In case you want a string, use a `--set`'s variant named `--set-string`. `--set-string foo=true` results in a string value of `"true"`. 374 375 `--set-file key=filepath` is another variant of `--set`. 376 It reads the file and use its content as a value. 377 An example use case of it is to inject a multi-line text into values without dealing with indentation in YAML. 378 Say you want to create a [brigade](https://github.com/Azure/brigade) project with certain value containing 5 lines JavaScript code, you might write a `values.yaml` like: 379 380 ```yaml 381 defaultScript: | 382 const { events, Job } = require("brigadier") 383 function run(e, project) { 384 console.log("hello default script") 385 } 386 events.on("run", run) 387 ``` 388 389 Being embedded in a YAML, this makes it harder for you to use IDE features and testing framework and so on that supports writing code. 390 Instead, you can use `--set-file defaultScript=brigade.js` with `brigade.js` containing: 391 392 ```javascript 393 const { events, Job } = require("brigadier") 394 function run(e, project) { 395 console.log("hello default script") 396 } 397 events.on("run", run) 398 ``` 399 400 ### More Installation Methods 401 402 The `helm install` command can install from several sources: 403 404 - A chart repository (as we've seen above) 405 - A local chart archive (`helm install foo-0.1.1.tgz`) 406 - An unpacked chart directory (`helm install path/to/foo`) 407 - A full URL (`helm install https://example.com/charts/foo-1.2.3.tgz`) 408 409 ## 'helm upgrade' and 'helm rollback': Upgrading a Release, and Recovering on Failure 410 411 When a new version of a chart is released, or when you want to change 412 the configuration of your release, you can use the `helm upgrade` 413 command. 414 415 An upgrade takes an existing release and upgrades it according to the 416 information you provide. Because Kubernetes charts can be large and 417 complex, Helm tries to perform the least invasive upgrade. It will only 418 update things that have changed since the last release. 419 420 ```console 421 $ helm upgrade -f panda.yaml happy-panda stable/mariadb 422 Fetched stable/mariadb-0.3.0.tgz to /Users/mattbutcher/Code/Go/src/k8s.io/helm/mariadb-0.3.0.tgz 423 happy-panda has been upgraded. 424 Last Deployed: Wed Sep 28 12:47:54 2016 425 Namespace: default 426 Status: DEPLOYED 427 ... 428 ``` 429 430 In the above case, the `happy-panda` release is upgraded with the same 431 chart, but with a new YAML file: 432 433 ```yaml 434 mariadbUser: user1 435 ``` 436 437 We can use `helm get values` to see whether that new setting took 438 effect. 439 440 ```console 441 $ helm get values happy-panda 442 mariadbUser: user1 443 ``` 444 445 The `helm get` command is a useful tool for looking at a release in the 446 cluster. And as we can see above, it shows that our new values from 447 `panda.yaml` were deployed to the cluster. 448 449 Now, if something does not go as planned during a release, it is easy to 450 roll back to a previous release using `helm rollback [RELEASE] [REVISION]`. 451 452 ```console 453 $ helm rollback happy-panda 1 454 ``` 455 456 The above rolls back our happy-panda to its very first release version. 457 A release version is an incremental revision. Every time an install, 458 upgrade, or rollback happens, the revision number is incremented by 1. 459 The first revision number is always 1. And we can use `helm history [RELEASE]` 460 to see revision numbers for a certain release. 461 462 ## Helpful Options for Install/Upgrade/Rollback 463 There are several other helpful options you can specify for customizing the 464 behavior of Helm during an install/upgrade/rollback. Please note that this 465 is not a full list of cli flags. To see a description of all flags, just run 466 `helm <command> --help`. 467 468 - `--timeout`: A value in seconds to wait for Kubernetes commands to complete 469 This defaults to 300 (5 minutes) 470 - `--wait`: Waits until all Pods are in a ready state, PVCs are bound, Deployments 471 have minimum (`Desired` minus `maxUnavailable`) Pods in ready state and 472 Services have an IP address (and Ingress if a `LoadBalancer`) before 473 marking the release as successful. It will wait for as long as the 474 `--timeout` value. If timeout is reached, the release will be marked as 475 `FAILED`. Note: In scenario where Deployment has `replicas` set to 1 and 476 `maxUnavailable` is not set to 0 as part of rolling update strategy, 477 `--wait` will return as ready as it has satisfied the minimum Pod in ready condition. 478 - `--no-hooks`: This skips running hooks for the command 479 - `--recreate-pods` (only available for `upgrade` and `rollback`): This flag 480 will cause all pods to be recreated (with the exception of pods belonging to 481 deployments) 482 483 ## 'helm delete': Deleting a Release 484 485 When it is time to uninstall or delete a release from the cluster, use 486 the `helm delete` command: 487 488 ```console 489 $ helm delete happy-panda 490 ``` 491 492 This will remove the release from the cluster. You can see all of your 493 currently deployed releases with the `helm list` command: 494 495 ```console 496 $ helm list 497 NAME VERSION UPDATED STATUS CHART 498 inky-cat 1 Wed Sep 28 12:59:46 2016 DEPLOYED alpine-0.1.0 499 ``` 500 501 From the output above, we can see that the `happy-panda` release was 502 deleted. 503 504 However, Helm always keeps records of what releases happened. Need to 505 see the deleted releases? `helm list --deleted` shows those, and `helm 506 list --all` shows all of the releases (deleted and currently deployed, 507 as well as releases that failed): 508 509 ```console 510 ⇒ helm list --all 511 NAME VERSION UPDATED STATUS CHART 512 happy-panda 2 Wed Sep 28 12:47:54 2016 DELETED mariadb-0.3.0 513 inky-cat 1 Wed Sep 28 12:59:46 2016 DEPLOYED alpine-0.1.0 514 kindred-angelf 2 Tue Sep 27 16:16:10 2016 DELETED alpine-0.1.0 515 ``` 516 517 Because Helm keeps records of deleted releases, a release name cannot be 518 re-used. (If you _really_ need to re-use a release name, you can use the 519 `--replace` flag, but it will simply re-use the existing release and 520 replace its resources.) 521 522 Note that because releases are preserved in this way, you can rollback a 523 deleted resource, and have it re-activate. 524 525 ## 'helm repo': Working with Repositories 526 527 So far, we've been installing charts only from the `stable` repository. 528 But you can configure `helm` to use other repositories. Helm provides 529 several repository tools under the `helm repo` command. 530 531 You can see which repositories are configured using `helm repo list`: 532 533 ```console 534 $ helm repo list 535 NAME URL 536 stable https://kubernetes-charts.storage.googleapis.com 537 local http://localhost:8879/charts 538 mumoshu https://mumoshu.github.io/charts 539 ``` 540 541 And new repositories can be added with `helm repo add`: 542 543 ```console 544 $ helm repo add dev https://example.com/dev-charts 545 ``` 546 547 Because chart repositories change frequently, at any point you can make 548 sure your Helm client is up to date by running `helm repo update`. 549 550 ## Creating Your Own Charts 551 552 The [Chart Development Guide](charts.md) explains how to develop your own 553 charts. But you can get started quickly by using the `helm create` 554 command: 555 556 ```console 557 $ helm create deis-workflow 558 Creating deis-workflow 559 ``` 560 561 Now there is a chart in `./deis-workflow`. You can edit it and create 562 your own templates. 563 564 As you edit your chart, you can validate that it is well-formatted by 565 running `helm lint`. 566 567 When it's time to package the chart up for distribution, you can run the 568 `helm package` command: 569 570 ```console 571 $ helm package deis-workflow 572 deis-workflow-0.1.0.tgz 573 ``` 574 575 And that chart can now easily be installed by `helm install`: 576 577 ```console 578 $ helm install ./deis-workflow-0.1.0.tgz 579 ... 580 ``` 581 582 Charts that are archived can be loaded into chart repositories. See the 583 documentation for your chart repository server to learn how to upload. 584 585 Note: The `stable` repository is managed on the [Helm Charts 586 GitHub repository](https://github.com/helm/charts). That project 587 accepts chart source code, and (after audit) packages those for you. 588 589 ## Tiller, Namespaces and RBAC 590 In some cases you may wish to scope Tiller or deploy multiple Tillers to a single cluster. Here are some best practices when operating in those circumstances. 591 592 1. Tiller can be [installed](install.md) into any namespace. By default, it is installed into kube-system. You can run multiple Tillers provided they each run in their own namespace. 593 2. Limiting Tiller to only be able to install into specific namespaces and/or resource types is controlled by Kubernetes [RBAC](https://kubernetes.io/docs/admin/authorization/rbac/) roles and rolebindings. You can add a service account to Tiller when configuring Helm via `helm init --service-account <NAME>`. You can find more information about that [here](rbac.md). 594 3. Release names are unique PER TILLER INSTANCE. 595 4. Charts should only contain resources that exist in a single namespace. 596 5. It is not recommended to have multiple Tillers configured to manage resources in the same namespace. 597 598 ## Conclusion 599 600 This chapter has covered the basic usage patterns of the `helm` client, 601 including searching, installation, upgrading, and deleting. It has also 602 covered useful utility commands like `helm status`, `helm get`, and 603 `helm repo`. 604 605 For more information on these commands, take a look at Helm's built-in 606 help: `helm help`. 607 608 In the next chapter, we look at the process of developing charts.