Skip to content

Commit 6a93826

Browse files
authored
Merge pull request #45322 from abrennan89/SRVKS-892
[SRVKS-892]: Add init container docs
2 parents f338726 + 5bed27c commit 6a93826

5 files changed

+105
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * /serverless/admin_guide/serverless-configuration.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="serverless-admin-init-containers_{context}"]
7+
= Enabling init containers
8+
9+
link:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/[Init containers] are specialized containers that are run before application containers in a pod. They are generally used to implement initialization logic for an application, which may include running setup scripts or downloading required configurations. You can enable the use of init containers for Knative services by modifying the `KnativeServing` custom resource (CR).
10+
11+
[NOTE]
12+
====
13+
Init containers may cause longer application start-up times and should be used with caution for serverless applications, which are expected to scale up and down frequently.
14+
====
15+
16+
.Prerequisites
17+
18+
* You have installed {ServerlessOperatorName} and Knative Serving on your cluster.
19+
20+
ifdef::openshift-enterprise[]
21+
* You have cluster administrator permissions.
22+
endif::[]
23+
24+
ifdef::openshift-dedicated[]
25+
* You have cluster or dedicated administrator permissions.
26+
endif::[]
27+
28+
.Procedure
29+
30+
* Enable the use of init containers by adding the `kubernetes.podspec-init-containers` flag to the `KnativeServing` CR:
31+
+
32+
.Example KnativeServing CR
33+
[source,yaml]
34+
----
35+
apiVersion: operator.knative.dev/v1alpha1
36+
kind: KnativeServing
37+
metadata:
38+
name: knative-serving
39+
spec:
40+
config:
41+
features:
42+
kubernetes.podspec-init-containers: enabled
43+
...
44+
----

modules/serverless-config-emptydir.adoc

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99

1010
`emptyDir` volumes are empty volumes that are created when a pod is created, and are used to provide temporary working disk space. `emptyDir` volumes are deleted when the pod they were created for is deleted.
1111

12-
The `"kubernetes.podspec-volumes-emptydir"` extension controls whether `emptyDir` volumes can be used with Knative Serving. To enable using `emptyDir` volumes, you must modify the `KnativeServing` custom resource (CR) to include the following YAML:
12+
The `kubernetes.podspec-volumes-emptydir` extension controls whether `emptyDir` volumes can be used with Knative Serving. To enable using `emptyDir` volumes, you must modify the `KnativeServing` custom resource (CR) to include the following YAML:
1313

14+
.Example KnativeServing CR
1415
[source,yaml]
1516
----
16-
...
17+
apiVersion: operator.knative.dev/v1alpha1
18+
kind: KnativeServing
19+
metadata:
20+
name: knative-serving
1721
spec:
1822
config:
1923
features:
20-
"kubernetes.podspec-volumes-emptydir": enabled
24+
kubernetes.podspec-volumes-emptydir: enabled
2125
...
2226
----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * /serverless/develop/serverless-applications.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="serverless-init-containers-apps_{context}"]
7+
= Configuring init containers
8+
9+
link:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/[Init containers] are specialized containers that are run before application containers in a pod. They are generally used to implement initialization logic for an application, which may include running setup scripts or downloading required configurations.
10+
11+
[NOTE]
12+
====
13+
Init containers may cause longer application start-up times and should be used with caution for serverless applications, which are expected to scale up and down frequently.
14+
====
15+
16+
Multiple init containers are supported in a single Knative service spec. Knative provides a default, configurable naming template if a template name is not provided. The init containers template can be set by adding an appropriate value in a Knative `Service` object spec.
17+
18+
.Prerequisites
19+
20+
* {ServerlessOperatorName} and Knative Serving are installed on your cluster.
21+
22+
* Before you can use init containers for Knative services, an administrator must add the `kubernetes.podspec-init-containers` flag to the `KnativeServing` custom resource (CR). See the {ServerlessProductName} "Global configuration" documentation for more information.
23+
24+
.Procedure
25+
26+
* Add the `initContainers` spec to a Knative `Service` object:
27+
+
28+
.Example service spec
29+
[source,yaml]
30+
----
31+
apiVersion: serving.knative.dev/v1
32+
kind: Service
33+
...
34+
spec:
35+
template:
36+
spec:
37+
initContainers:
38+
- imagePullPolicy: IfNotPresent <1>
39+
image: <image_uri> <2>
40+
volumeMounts: <3>
41+
- name: data
42+
mountPath: /data
43+
...
44+
----
45+
<1> The link:https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy[image pull policy] when the image is downloaded.
46+
<2> The URI for the init container image.
47+
<3> The location where volumes are mounted within the container file system.

serverless/admin_guide/serverless-configuration.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ The `spec.config` in the Knative custom resources have one `<name>` entry for ea
1616
include::modules/serverless-channel-default.adoc[leveloffset=+1]
1717

1818
// Knative Serving
19+
// deployments
1920
include::modules/knative-serving-CR-system-deployments.adoc[leveloffset=+1]
21+
// enable emptydirs
2022
include::modules/serverless-config-emptydir.adoc[leveloffset=+1]
2123
// global https redirect
2224
include::modules/serverless-https-redirect-global.adoc[leveloffset=+1]
@@ -26,6 +28,8 @@ include::modules/serverless-url-scheme-external-routes.adoc[leveloffset=+1]
2628
include::modules/serverless-kourier-gateway-service-type.adoc[leveloffset=+1]
2729
// Enabling PVC for Serving
2830
include::modules/serverless-enabling-pvc-support.adoc[leveloffset=+1]
31+
// enable init containers
32+
include::modules/serverless-admin-init-containers.adoc[leveloffset=+1]
2933

3034
ifdef::openshift-enterprise[]
3135
[id="additional-resources_knative-serving-CR-config"]

serverless/develop/serverless-applications.adoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ ifdef::openshift-enterprise[]
5757
// Using Knative services w/ restrictive NetworkPolicies
5858
include::modules/serverless-services-network-policies.adoc[leveloffset=+1]
5959
endif::[]
60-
// should maybe move to admin guide? asked serving team
60+
// move to admin guide, outside scope of this PR
6161

62+
// config init containers
63+
include::modules/serverless-init-containers-apps.adoc[leveloffset=+1]
6264
// HTTPS redirection
6365
include::modules/serverless-https-redirect-service.adoc[leveloffset=+1]
64-
// asked serving team why a user would need this for abstract rewrite, waiting for details
6566

6667
[id="additional-resources_serverless-applications"]
6768
[role="_additional-resources"]

0 commit comments

Comments
 (0)