Can I use YAML anchors with Okteto?

I have a very large YAML configuration, with a lot of repeated values. Is it possible to use anchors and aliases to keep my manifest simpler?

If you have repeated sections in your okteto.yml file, you might like to use YAML anchors. They can reduce effort and make updating in bulk, easier.

Anchors and aliases

There are 2 parts to this:

  • The anchor ‘&’ which defines a chunk of configuration
  • The alias ‘*’ used to refer to that chunk elsewhere

So in the example below we use &go-volumes to define the volumes of my go dev container, which has several lines for reuse:

volumes: &go-volumes
      - /go/
      - /root/.cache/
      - /root/.vscode-server

and the alias *go-volumes to reuse it.

volumes: *go-volumes

YAML anchors and aliases cannot contain the ’ [ ', ’ ] ', ’ { ', ’ } ', and ’ , ’ characters.

Override values

But what if you want essentially the same block with one small change?

You can use overrides with the characters ‘<<:’ to add more values, or override existing ones.

Put it all together

Using the techniques above, you can reduce the amount of effort needed to create your okteto manifest, and maintain it when changes occur.

As with all YAML it’s vital to make sure your indentation is correct, which is tricky when using anchors, so take care!