Skip to content

Instantly share code, notes, and snippets.

@bryanl
Created June 29, 2018 00:30
Show Gist options
  • Select an option

  • Save bryanl/30fb189f8f3f59b2ef0d810be9b76e1f to your computer and use it in GitHub Desktop.

Select an option

Save bryanl/30fb189f8f3f59b2ef0d810be9b76e1f to your computer and use it in GitHub Desktop.
ksonnet helm parameters

ksonnet and param values with Helm.

Initializing the ksonnet application and Helm

  1. ks init app
  2. cd ksapp
  3. ks registry add helm-stable https://kubernetes-charts.storage.googleapis.com
  4. ks pkg add helm-stable/redis
  5. ks generate helm-stable-redis redis

Overriding Helm values

To get a list of the default values for a Helm Chart, you can use ks inspect values stable/redis. This will will return the values in YAML format. To override these values, use ks param set <component name> values.<value name> <new value>

  • To update the count of redis slaves, run ks param set redis values.cluster.slaveCount 3
  • To add a pull secret, run ks param set redis values.image.pullSecrets '["ourSecret"]'

You can view values with override values using ks param list and ks show default to review the configuration.

ksonnet params

ksonnet uses params to allow users to have knobs to adjust their configurations. There are currently four types of parameters:

  • component - ks param set component name value These are the defaults.
  • component global (don't ever use this)
  • environment - ks param set component name value --env default These override component parameters in an environment
  • environment global - ks param set name value --env default These are applied to every object created an environment

Param values can be one of the following:

  • literal: string, float, int e.g. 1
  • array: e.g. [1,2,3,4]
  • object: e.g. {"project": "engineering"} note enclose arrays and objects in single quotes to avoid the shell trying to interpret them.

Overriding environment parameters

ksonnet has the ability to apply configurations to every object in an environment. This can be used to annotate object ownership in a cluster.

ks param set metadata.labels '{"project": "engineering"}' --env default sets a project label on all created objects. You can view these options with ks env list default --env default

This feature is not fully baked. It does work with components that return arrays (as the redis example above does. This will be fixed by 0.12 release.

ksonnet overlays (future feature ~0.13 timeframe)

With ksonnet, you can apply any object transform allowed by Jsonnet. For instance, you could add a sidecar to all Deployments. To make this happen, we'll need a way to target objects created by Helm. Helm will always return a n array of Kubernetes objects, so we can build a API that can update this array. For instance.

// import ksonnet API as an extVar so we can change it as needed
local ksonnet = std.extVar("__ksonnet/api");
// an API that can add sidecars to deployments
local sidecarAPI =  import("foo/bar/sidecar.jsonnet");
// helm renders our objects
local objects = std.prune(std.native(...));
// our custom update function to create a new, updated object
local update(obj) = obj + sidecarAPI  

// this will return objects with the updated object
objects + ksonnet.withObject("extensions/v1beta1", "Deployment", "redis-slave", update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment