Initcontainers
Define an init container for your Workload.
This example shows how developers may define initContainers
using a
Humanitec Score Extension file
and the
Pod feature
. This feature lets you specify any part of the Kubernetes PodSpec
, including initContainers
.
To manage init containers centrally through the Platform Engineering team and shift the task away from developers, take a look at the Resource Definition example on init containers .
Use this command to deploy the example:
humctl score deploy \
--app ${HUMANITEC_APP} --env ${HUMANITEC_ENV} \
--extensions humanitec.score.yaml
humanitec.score.yaml
(
view on GitHub
)
:
# This Score Extension file adds an initContainer polling a local service
apiVersion: humanitec.org/v1b1
profile: humanitec/default-module
spec:
pod:
initContainers:
- name: init-myservice
image: busybox
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"]
score.yaml
(
view on GitHub
)
:
# This Score file deploys a sample workload with a service.
# The initContainer defined through the Score Extension file polls for the existence of this service
apiVersion: score.dev/v1b1
metadata:
name: myservice
containers:
demo:
image: nginx
service:
ports:
www:
port: 8080
targetPort: 80