Overrides

Create local overrides to application configurations

Overview

Applications in ksonnet that are version controlled with Git can have local overrides.

Overrides provide a way to modify ksonnet environments locally without changing the settings in version control.

This is useful for testing locally in parallel with working on changes to be shared.

Create an override

Create a new environment with an --override flag. The environment will use the current kubeconfig context unless specified otherwise.

A new config file called app.override.yaml should be available in the root of the ksonnet application. This file automatically added to .gitignore and will not be tracked by Git.

If an existing environment conflicts with an override, the override take takes priority.

For example, the default environment name can be overridden with a different server address, k8s version, or namespace.

$ ks init app
$ ks env list
NAME    OVERRIDE KUBERNETES-VERSION NAMESPACE SERVER
====    ======== ================== ========= ======
default          v1.10.0            default   https://192.168.99.100:8443

$ ks env add default --override --server https://192.168.99.101:8443 --api-spec version:v1.8.0
$ ks env list
NAME    OVERRIDE KUBERNETES-VERSION NAMESPACE SERVER
====    ======== ================== ========= ======
default *        v1.8.0             default   https://192.168.99.101:8443

Manage overrides

Environments created from an override will be marked with an asterisk. Create an environment override with the shorter -o flag.

$ ks init app
$ ks env add testing -o
$ ks env list
NAME    OVERRIDE KUBERNETES-VERSION NAMESPACE SERVER
====    ======== ================== ========= ======
default          v1.10.0            default   https://192.168.99.100:8443
testing *        v1.10.0            default   https://192.168.99.100:8443

Examination of app.override.yaml shows it is quite similar to app.yaml. Adding a registry or environment targets can be done with overrides. app.override.yaml will capture that information as registry/targets are added or removed.

app.override.yaml
1
2
3
4
5
6
7
8
9
apiVersion: 0.2.0
environments:
  testing:
    destination:
      namespace: default
      server: https://192.168.99.100:8443
    k8sVersion: v1.10.0
    path: testing
kind: ksonnet.io/app-override

Add a registry

Adding a registry to an overridden environment will modify the registry reference to app.override.yaml.

$ ks registry add incubator https://github.com/ksonnet/parts/tree/master/incubator -o

Observe how the registry name, protocol, and URI are added to app.override.yaml.

app.override.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: 0.2.0
environments:
  testing:
    destination:
      namespace: default
      server: https://192.168.99.100:8443
    k8sVersion: v1.10.0
    path: testing
kind: ksonnet.io/app-override
registries:
  incubator:
    protocol: github
    uri: https://github.com/ksonnet/parts/tree/master/incubator

Remove an overridden environment

The override flag must be passed explicitly in order to remove an environment from an override.

$ ks env rm testing
INFO Deleting environment "testing" with metadata at path "$HOME/app/environments/testing"
ERROR environment "testing" does not exist

$ ks env rm testing -o
INFO Deleting environment "testing" with metadata at path "$HOME/app/environments/testing"
INFO Successfully removed environment 'testing'

Overrides provide a quick way to leverage existing ksonnet applications in a testing environment while having minimal impact to the application.

Last updated on: September 4, 2018