Skip to main content
Version: v0.10 🚧

Configure Containers

You can manage container-level configurations in the AppConfiguration model via the containers field (under the workload schemas). By default, everything defined in the containers field will be treated as application containers. Sidecar containers will be supported in a future version of kusion.

For the full Container schema reference, please see here for more details.

Pre-requisite

Please refer to the prerequisites in the guide for deploying an application.

The example below also requires you to have initialized the project using the kusion workspace create and kusion init command, which will create a workspace and also generate a kcl.mod file under the stack directory.

Managing Workspace Configuration

In the last guide, we introduced a step to initialize a workspace with an empty configuration. The same empty configuration will still work in this guide, no changes are required there.

Example

simple-service/dev/main.k:

import catalog.models.schema.v1 as ac
import catalog.models.schema.v1.workload as wl
import catalog.models.schema.v1.workload.container as c
import catalog.models.schema.v1.workload.container.probe as p
import catalog.models.schema.v1.workload.network as n

helloworld: ac.AppConfiguration {
workload: wl.Service {
containers: {
"helloworld": c.Container {
image: "gcr.io/google-samples/gb-frontend:v4"
env: {
"env1": "VALUE"
"env2": "VALUE2"
}
resources: {
"cpu": "500m"
"memory": "512M"
}
# Configure an HTTP readiness probe
readinessProbe: p.Probe {
probeHandler: p.Http {
url: "http://localhost:80"
}
initialDelaySeconds: 10
}
}
}
replicas: 2
ports: [
n.Port {
port: 80
}
]
}
}

Apply

Re-run steps in Applying, new container configuration can be applied.

$ kusion apply
✔︎ Generating Intent in the Stack dev...
Stack: dev ID Action
* ├─ v1:Namespace:simple-service UnChanged
* ├─ v1:Service:simple-service:simple-service-dev-helloworld-private UnChanged
* └─ apps/v1:Deployment:simple-service:simple-service-dev-helloworld Update


? Do you want to apply these diffs? yes
Start applying diffs ...
SUCCESS UnChanged v1:Namespace:simple-service, skip
SUCCESS UnChanged v1:Service:simple-service:simple-service-dev-helloworld-private, skip
SUCCESS Update apps/v1:Deployment:simple-service:simple-service-dev-helloworld success
Update apps/v1:Deployment:simple-service:simple-service-dev-helloworld success [3/3] ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ 100% | 0s
Apply complete! Resources: 0 created, 1 updated, 0 deleted.

Validation

We can verify the container (in the deployment template) now has the updated attributes as defined in the container configuration:

$ kubectl get deployment -n simple-service -o yaml
...
template:
...
spec:
containers:
- env:
- name: env1
value: VALUE
- name: env2
value: VALUE2
image: gcr.io/google-samples/gb-frontend:v4
imagePullPolicy: IfNotPresent
name: helloworld
readinessProbe:
failureThreshold: 3
httpGet:
host: localhost
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
cpu: 500m
memory: 512M
...