github.com/felipejfc/helm@v2.1.2+incompatible/docs/charts.md (about)

     1  # Charts
     2  
     3  Helm uses a packaging format called _charts_. A chart is a collection of files
     4  that describe a related set of Kubernetes resources. A single chart
     5  might be used to deploy something simple, like a memcached pod, or
     6  something complex, like a full web app stack with HTTP servers,
     7  databases, caches, and so on.
     8  
     9  Charts are created as files laid out in a particular directory tree,
    10  then they can be packaged into versioned archives to be deployed.
    11  
    12  This document explains the chart format, and provides basic guidance for
    13  building charts with Helm.
    14  
    15  ## The Chart File Structure
    16  
    17  A chart is organized as a collection of files inside of a directory. The
    18  directory name is the name of the chart (without versioning information). Thus,
    19  a chart describing Wordpress would be stored in the `wordpress/` directory.
    20  
    21  Inside of this directory, Helm will expect a structure that matches this:
    22  
    23  ```
    24  wordpress/
    25    Chart.yaml          # A YAML file containing information about the chart
    26    LICENSE             # OPTIONAL: A plain text file containing the license for the chart
    27    README.md           # OPTIONAL: A human-readable README file
    28    values.yaml         # The default configuration values for this chart
    29    charts/             # OPTIONAL: A directory containing any charts upon which this chart depends.
    30    templates/          # OPTIONAL: A directory of templates that, when combined with values,
    31                        # will generate valid Kubernetes manifest files.
    32    templates/NOTES.txt # OPTIONAL: A plain text file containing short usage notes
    33  ```
    34  
    35  Helm reserves use of the `charts/` and `templates/` directories, and of
    36  the listed file names. Other files will be left as they are.
    37  
    38  ## The Chart.yaml File
    39  
    40  The `Chart.yaml` file is required for a chart. It contains the following fields:
    41  
    42  ```yaml
    43  name: The name of the chart (required)
    44  version: A SemVer 2 version (required)
    45  description: A single-sentence description of this project (optional)
    46  keywords:
    47    - A list of keywords about this project (optional)
    48  home: The URL of this project's home page (optional)
    49  sources:
    50    - A list of URLs to source code for this project (optional)
    51  maintainers: # (optional)
    52    - name: The maintainer's name (required for each maintainer)
    53      email: The maintainer's email (optional for each maintainer)
    54  engine: gotpl # The name of the template engine (optional, defaults to gotpl)
    55  icon: A URL to an SVG or PNG image to be used as an icon (optional).
    56  ```
    57  
    58  If you are familiar with the `Chart.yaml` file format for Helm Classic, you will
    59  notice that fields specifying dependencies have been removed. That is because
    60  the new Chart format expresses dependencies using the `charts/` directory.
    61  
    62  Other fields will be silently ignored.
    63  
    64  ### Charts and Versioning
    65  
    66  Every chart must have a version number. A version must follow the
    67  [SemVer 2](http://semver.org/) standard. Unlike Helm Classic, Kubernetes
    68  Helm uses version numbers as release markers. Packages in repositories
    69  are identified by name plus version.
    70  
    71  For example, an `nginx` chart whose version field is set to `version:
    72  1.2.3` will be named:
    73  
    74  ```
    75  nginx-1.2.3.tgz
    76  ```
    77  
    78  More complex SemVer 2 names are also supported, such as
    79  `version: 1.2.3-alpha.1+ef365`. But non-SemVer names are explicitly
    80  disallowed by the system.
    81  
    82  **NOTE:** Whereas Helm Classic and Deployment Manager were both
    83  very GitHub oriented when it came to charts, Kubernetes Helm does not
    84  rely upon or require GitHub or even Git. Consequently, it does not use
    85  Git SHAs for versioning at all.
    86  
    87  The `version` field inside of the `Chart.yaml` is used by many of the
    88  Helm tools, including the CLI and the Tiller server. When generating a
    89  package, the `helm package` command will use the version that it finds
    90  in the `Chart.yaml` as a token in the package name. The system assumes
    91  that the version number in the chart package name matches the version number in
    92  the `Chart.yaml`. Failure to meet this assumption will cause an error.
    93  
    94  ## Chart LICENSE, README and NOTES
    95  
    96  Charts can also contain files that describe the installation, configuration, usage and license of a
    97  chart. A README for a chart should be formatted in Markdown (README.md), and should generally
    98  contain:
    99  
   100  - A description of the application or service the chart provides
   101  - Any prerequisites or requirements to run the chart
   102  - Descriptions of options in `values.yaml` and default values
   103  - Any other information that may be relevant to the installation or configuration of the chart
   104  
   105  The chart can also contain a short plain text `templates/NOTES.txt` file that will be printed out
   106  after installation, and when viewing the status of a release. This file is evaluated as a
   107  [template](#templates-and-values), and can be used to display usage notes, next steps, or any other
   108  information relevant to a release of the chart. For example, instructions could be provided for
   109  connecting to a database, or accessing a web UI. Since this file is printed to STDOUT when running
   110  `helm install` or `helm status`, it is recommended to keep the content brief and point to the README
   111  for greater detail.
   112  
   113  ## Chart Dependencies
   114  
   115  In Helm, one chart may depend on any number of other charts. These
   116  dependencies are expressed explicitly by copying the dependency charts
   117  into the `charts/` directory.
   118  
   119  A dependency can be either a chart archive (`foo-1.2.3.tgz`) or an
   120  unpacked chart directory. But its name cannot start with `_` or `.`.
   121  Such files are ignored by the chart loader.
   122  
   123  **Note:** The `dependencies:` section of the `Chart.yaml` from Helm
   124  Classic has been completely removed.
   125  
   126  For example, if the Wordpress chart depends on the Apache chart, the
   127  Apache chart (of the correct version) is supplied in the Wordpress
   128  chart's `charts/` directory:
   129  
   130  ```
   131  wordpress:
   132    Chart.yaml
   133    requirements.yaml
   134    # ...
   135    charts/
   136      apache/
   137        Chart.yaml
   138        # ...
   139      mysql/
   140        Chart.yaml
   141        # ...
   142  ```
   143  
   144  The example above shows how the Wordpress chart expresses its dependency
   145  on Apache and MySQL by including those charts inside of its `charts/`
   146  directory.
   147  
   148  **TIP:** _To drop a dependency into your `charts/` directory, use the
   149  `helm fetch` command or use a `requirements.yaml` file_
   150  
   151  ### Managing Dependencies with `requirements.yaml`
   152  
   153  While Helm will allow you to manually manage your dependencies, the
   154  preferred method of declaring dependencies is by using a
   155  `requirements.yaml` file inside of your chart.
   156  
   157  A `requirements.yaml` file is a simple file for listing your
   158  dependencies.
   159  
   160  ```yaml
   161  dependencies:
   162    - name: apache
   163      version: 1.2.3
   164      repository: http://example.com/charts
   165    - name: mysql
   166      version: 3.2.1
   167      repository: http://another.example.com/charts
   168  ```
   169  
   170  - The `name` field is the name of the chart you want.
   171  - The `version` field is the version of the chart you want.
   172  - The `repository` field is the full URL to the chart repository. Note
   173    that you must also use `helm repo add` to add that repo locally.
   174  
   175  Once you have a dependencies file, you can run `helm dependency update`
   176  and it will use your dependency file to download all of the specified
   177  charts into your `charts/` directory for you.
   178  
   179  ```console
   180  $ helm dep up foochart
   181  Hang tight while we grab the latest from your chart repositories...
   182  ...Successfully got an update from the "local" chart repository
   183  ...Successfully got an update from the "stable" chart repository
   184  ...Successfully got an update from the "example" chart repository
   185  ...Successfully got an update from the "another" chart repository
   186  Update Complete. Happy Helming!
   187  Saving 2 charts
   188  Downloading apache from repo http://example.com/charts
   189  Downloading mysql from repo http://another.example.com/charts
   190  ```
   191  
   192  When `helm dependency update` retrieves charts, it will store them as
   193  chart archives in the `charts/` directory. So for the example above, one
   194  would expect to see the following files in the charts directory:
   195  
   196  ```
   197  charts/
   198    apache-1.2.3.tgz
   199    mysql-3.2.1.tgz
   200  ```
   201  
   202  Managing charts with `requirements.yaml` is a good way to easily keep
   203  charts updated, and also share requirements information throughout a
   204  team.
   205  
   206  ## Templates and Values
   207  
   208  Helm Chart templates are written in the
   209  [Go template language](https://golang.org/pkg/text/template/), with the
   210  addition of 50 or so add-on template
   211  functions [from the Sprig library](https://github.com/Masterminds/sprig) and a
   212  few other [specialized functions](charts_tips_and_tricks.md).
   213  
   214  All template files are stored in a chart's `templates/` folder. When
   215  Helm renders the charts, it will pass every file in that directory
   216  through the template engine.
   217  
   218  Values for the templates are supplied two ways:
   219  
   220    - Chart developers may supply a file called `values.yaml` inside of a
   221      chart. This file can contain default values.
   222    - Chart users may supply a YAML file that contains values. This can be
   223      provided on the command line with `helm install`.
   224  
   225  When a user supplies custom values, these values will override the
   226  values in the chart's `values.yaml` file.
   227  
   228  ### Template Files
   229  
   230  Template files follow the standard conventions for writing Go templates
   231  (see [the text/template Go package documentation](https://golang.org/pkg/text/template/)
   232  for details).
   233  An example template file might look something like this:
   234  
   235  ```yaml
   236  apiVersion: v1
   237  kind: ReplicationController
   238  metadata:
   239    name: deis-database
   240    namespace: deis
   241    labels:
   242      heritage: deis
   243  spec:
   244    replicas: 1
   245    selector:
   246      app: deis-database
   247    template:
   248      metadata:
   249        labels:
   250          app: deis-database
   251      spec:
   252        serviceAccount: deis-database
   253        containers:
   254          - name: deis-database
   255            image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}
   256            imagePullPolicy: {{.Values.pullPolicy}}
   257            ports:
   258              - containerPort: 5432
   259            env:
   260              - name: DATABASE_STORAGE
   261                value: {{default "minio" .Values.storage}}
   262  ```
   263  
   264  The above example, based loosely on [https://github.com/deis/charts](https://github.com/deis/charts), is a template for a Kubernetes replication controller.
   265  It can use the following four template values (usually defined in a
   266  `values.yaml` file):
   267  
   268  - `imageRegistry`: The source registry for the Docker image.
   269  - `dockerTag`: The tag for the docker image.
   270  - `pullPolicy`: The Kubernetes pull policy.
   271  - `storage`: The storage backend, whose default is set to `"minio"`
   272  
   273  All of these values are defined by the template author. Helm does not
   274  require or dictate parameters.
   275  
   276  To see many working charts, check out the [Kubernetes Charts
   277  project](https://github.com/kubernetes/charts)
   278  
   279  ### Predefined Values
   280  
   281  Values that are supplied via a `values.yaml` file (or via the `--set`
   282  flag) are accessible from the `.Values` object in a template. But there
   283  are other pre-defined pieces of data you can access in your templates.
   284  
   285  The following values are pre-defined, are available to every template, and
   286  cannot be overridden. As with all values, the names are _case
   287  sensitive_.
   288  
   289  - `Release.Name`: The name of the release (not the chart)
   290  - `Release.Time`: The time the chart release was last updated. This will
   291    match the `Last Released` time on a Release object.
   292  - `Release.Namespace`: The namespace the chart was released to.
   293  - `Release.Service`: The service that conducted the release. Usually
   294    this is `Tiller`.
   295  - `Chart`: The contents of the `Chart.yaml`. Thus, the chart version is
   296    obtainable as `Chart.Version` and the maintainers are in
   297    `Chart.Maintainers`.
   298  - `Files`: A map-like object containing all non-special files in the chart. This
   299    will not give you access to templates, but will give you access to additional
   300    files that are present. Files can be accessed using `{{index .Files "file.name"}}`
   301    or using the `{{.Files.Get name}}` or `{{.Files.GetString name}}` functions. You can
   302    also access the contents of the file as `[]byte` using `{{.Files.GetBytes}}`
   303  
   304  **NOTE:** Any unknown Chart.yaml fields will be dropped. They will not
   305  be accessible inside of the `Chart` object. Thus, Chart.yaml cannot be
   306  used to pass arbitrarily structured data into the template. The values
   307  file can be used for that, though.
   308  
   309  ### Values files
   310  
   311  Considering the template in the previous section, a `values.yaml` file
   312  that supplies the necessary values would look like this:
   313  
   314  ```yaml
   315  imageRegistry: "quay.io/deis"
   316  dockerTag: "latest"
   317  pullPolicy: "alwaysPull"
   318  storage: "s3"
   319  ```
   320  
   321  A values file is formatted in YAML. A chart may include a default
   322  `values.yaml` file. The Helm install command allows a user to override
   323  values by supplying additional YAML values:
   324  
   325  ```console
   326  $ helm install --values=myvals.yaml wordpress
   327  ```
   328  
   329  When values are passed in this way, they will be merged into the default
   330  values file. For example, consider a `myvals.yaml` file that looks like
   331  this:
   332  
   333  ```yaml
   334  storage: "gcs"
   335  ```
   336  
   337  When this is merged with the `values.yaml` in the chart, the resulting
   338  generated content will be:
   339  
   340  ```yaml
   341  imageRegistry: "quay.io/deis"
   342  dockerTag: "latest"
   343  pullPolicy: "alwaysPull"
   344  storage: "gcs"
   345  ```
   346  
   347  Note that only the last field was overridden.
   348  
   349  **NOTE:** The default values file included inside of a chart _must_ be named
   350  `values.yaml`. But files specified on the command line can be named
   351  anything.
   352  
   353  **NOTE:** If the `--set` flag is used on `helm install` or `helm upgrade`, those
   354  values are simply converted to YAML on the client side.
   355  
   356  Any of these values are then accessible inside of templates using the
   357  `.Values` object:
   358  
   359  ```yaml
   360  apiVersion: v1
   361  kind: ReplicationController
   362  metadata:
   363    name: deis-database
   364    namespace: deis
   365    labels:
   366      heritage: deis
   367  spec:
   368    replicas: 1
   369    selector:
   370      app: deis-database
   371    template:
   372      metadata:
   373        labels:
   374          app: deis-database
   375      spec:
   376        serviceAccount: deis-database
   377        containers:
   378          - name: deis-database
   379            image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}
   380            imagePullPolicy: {{.Values.pullPolicy}}
   381            ports:
   382              - containerPort: 5432
   383            env:
   384              - name: DATABASE_STORAGE
   385                value: {{default "minio" .Values.storage}}
   386  
   387  ```
   388  
   389  ### Scope, Dependencies, and Values
   390  
   391  Values files can declare values for the top-level chart, as well as for
   392  any of the charts that are included in that chart's `charts/` directory.
   393  Or, to phrase it differently, a values file can supply values to the
   394  chart as well as to any of its dependencies. For example, the
   395  demonstration Wordpress chart above has both `mysql` and `apache` as
   396  dependencies. The values file could supply values to all of these
   397  components:
   398  
   399  ```yaml
   400  title: "My Wordpress Site" # Sent to the Wordpress template
   401  
   402  mysql:
   403    max_connections: 100 # Sent to MySQL
   404    password: "secret"
   405  
   406  apache:
   407    port: 8080 # Passed to Apache
   408  ```
   409  
   410  Charts at a higher level have access to all of the variables defined
   411  beneath. So the wordpress chart can access the MySQL password as
   412  `.Values.mysql.password`. But lower level charts cannot access things in
   413  parent charts, so MySQL will not be able to access the `title` property. Nor,
   414  for that matter, can it access `apache.port`.
   415  
   416  Values are namespaced, but namespaces are pruned. So for the Wordpress
   417  chart, it can access the MySQL password field as `.Values.mysql.password`. But
   418  for the MySQL chart, the scope of the values has been reduced and the
   419  namespace prefix removed, so it will see the password field simply as
   420  `.Values.password`.
   421  
   422  #### Global Values
   423  
   424  As of 2.0.0-Alpha.2, Helm supports special "global" value. Consider
   425  this modified version of the previous example:
   426  
   427  ```yaml
   428  title: "My Wordpress Site" # Sent to the Wordpress template
   429  
   430  global:
   431    app: MyWordpress
   432  
   433  mysql:
   434    max_connections: 100 # Sent to MySQL
   435    password: "secret"
   436  
   437  apache:
   438    port: 8080 # Passed to Apache
   439  ```
   440  
   441  The above adds a `global` section with the value `app: MyWordpress`.
   442  This value is available to _all_ charts as `.Values.global.app`.
   443  
   444  For example, the `mysql` templates may access `app` as `{{.Values.global.app}}`, and
   445  so can the `apache` chart. Effectively, the values file above is
   446  regenerated like this:
   447  
   448  ```yaml
   449  title: "My Wordpress Site" # Sent to the Wordpress template
   450  
   451  global:
   452    app: MyWordpress
   453  
   454  mysql:
   455    global:
   456      app: MyWordpress
   457    max_connections: 100 # Sent to MySQL
   458    password: "secret"
   459  
   460  apache:
   461    global:
   462      app: MyWordpress
   463    port: 8080 # Passed to Apache
   464  ```
   465  
   466  This provides a way of sharing one top-level variable with all
   467  subcharts, which is useful for things like setting `metadata` properties
   468  like labels.
   469  
   470  If a subchart declares a global variable, that global will be passed
   471  _downward_ (to the subchart's subcharts), but not _upward_ to the parent
   472  chart. There is no way for a subchart to influence the values of the
   473  parent chart.
   474  
   475  _Global sections are restricted to only simple key/value pairs. They do
   476  not support nesting._
   477  
   478  For example, the following is **illegal** and will not work:
   479  
   480  ```yaml
   481  global:
   482    foo:  # It is illegal to nest an object inside of global.
   483      bar: baz
   484  ```
   485  
   486  ### References
   487  
   488  When it comes to writing templates and values files, there are several
   489  standard references that will help you out.
   490  
   491  - [Go templates](https://godoc.org/text/template)
   492  - [Extra template functions](https://godoc.org/github.com/Masterminds/sprig)
   493  - [The YAML format](http://yaml.org/spec/)
   494  
   495  ## Using Helm to Manage Charts
   496  
   497  The `helm` tool has several commands for working with charts.
   498  
   499  It can create a new chart for you:
   500  
   501  ```console
   502  $ helm create mychart
   503  Created mychart/
   504  ```
   505  
   506  Once you have edited a chart, `helm` can package it into a chart archive
   507  for you:
   508  
   509  ```console
   510  $ helm package mychart
   511  Archived mychart-0.1.-.tgz
   512  ```
   513  
   514  You can also use `helm` to help you find issues with your chart's
   515  formatting or information:
   516  
   517  ```console
   518  $ helm lint mychart
   519  No issues found
   520  ```
   521  
   522  ## Chart Repositories
   523  
   524  A _chart repository_ is an HTTP server that houses one or more packaged
   525  charts. While `helm` can be used to manage local chart directories, when
   526  it comes to sharing charts, the preferred mechanism is a chart
   527  repository.
   528  
   529  Any HTTP server that can serve YAML files and tar files and can answer
   530  GET requests can be used as a repository server.
   531  
   532  Helm comes with built-in package server for developer testing (`helm
   533  serve`). The Helm team has tested other servers, including Google Cloud
   534  Storage with website mode enabled, and S3 with website mode enabled.
   535  
   536  A repository is characterized primarily by the presence of a special
   537  file called `index.yaml` that has a list of all of the packages supplied
   538  by the repository, together with metadata that allows retrieving and
   539  verifying those packages.
   540  
   541  On the client side, repositories are managed with the `helm repo`
   542  commands. However, Helm does not provide tools for uploading charts to
   543  remote repository servers. This is because doing so would add
   544  substantial requirements to an implementing server, and thus raise the
   545  barrier for setting up a repository.
   546  
   547  ## Chart Starter Packs
   548  
   549  The `helm create` command takes an optional `--starter` option that lets you
   550  specify a "starter chart".
   551  
   552  Starters are just regular charts, but are located in `$HELM_HOME/starters`.
   553  As a chart developer, you may author charts that are specifically designed
   554  to be used as starters. Such charts should be designed with the following
   555  considerations in mind:
   556  
   557  - The `Chart.yaml` will be overwritten by the genertor.
   558  - Users will expect to modify such a chart's contents, so documentation
   559    should indicate how users can do so.
   560  
   561  Currently the only way to add a chart to `$HELM_HOME/starters` is to manually
   562  copy it there. In your chart's documentation, you may want to explain that
   563  process.