Resource Definitions
Driver
Capability
Flavor
Resource Type
Initcontainers
This section contains example Resource Definitions using the Template Driver for defining an init container on your Pods.
While it is also possible to set init containers via Score , the approach shown here shifts the management of init containers down to the Platform, ensuring consistency and relieving developers of the task to repeat them for each Workload in the Score extension file.
custom-workload-with-initcontainer.yaml
: Add the required init container to the Workload so it polls for the existence of a Kubernetes service for the Workload. This format is for use with the Humanitec CLI .custom-workload-with-initcontainer.tf
: This format is for use with the Humanitec Terraform Provider .
Resource Definitions #
custom-workload-with-initcontainer.yaml
(
view on GitHub
)
:
# This Resource Definition uses the Template Driver to add an init container to a Workload
apiVersion: entity.humanitec.io/v1b1
kind: Definition
metadata:
id: custom-workload-with-initcontainer
entity:
name: custom-workload-with-initcontainer
type: workload
driver_type: humanitec/template
driver_inputs:
values:
templates:
outputs: |
update:
- op: add
path: /spec/pod/initContainers
value:
- command:
- sh
- -c
- until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done
image: busybox
name: init-myservice
# Set matching criteria as required
criteria:
- app_id: my-app
custom-workload-with-initcontainer.tf
(
view on GitHub
)
:
resource "humanitec_resource_definition" "custom-workload-with-initcontainer" {
driver_type = "humanitec/template"
id = "custom-workload-with-initcontainer"
name = "custom-workload-with-initcontainer"
type = "workload"
driver_inputs = {
values_string = jsonencode({
"templates" = {
"outputs" = <<END_OF_TEXT
update:
- op: add
path: /spec/pod/initContainers
value:
- command:
- sh
- -c
- until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done
image: busybox
name: init-myservice
END_OF_TEXT
}
})
}
}
resource "humanitec_resource_definition_criteria" "custom-workload-with-initcontainer_criteria_0" {
resource_definition_id = resource.humanitec_resource_definition.custom-workload-with-initcontainer.id
app_id = "my-app"
}