How to customize the manifests for Knative Operator with a local volume

Vincent Hou
3 min readJul 22, 2021

The artifacts released by Knative serving and eventing consist of many Kubernetes resources, meaning there are combination many enough to configure Knative. The custom resources of Knative Operator enable different fields for configuration, but it is almost impossible for them to enable all the possible options. What if you want to configure something that the CRs of Knative operator do not support? Knative operator offers you an omnipotent way to manipulate the resources by supporting customized manifests. You can either overwrite all the resources or partially update or add some resources.

You can save the resources in a file of the yaml format and publish it accessible online for the Knative Operator to retrieve. However, there is an alternative way by mounting a local volume to the deployment resource of Knative Operator.

There is a Gateway resource named knative-ingress-gateway available in the network istio plugin, that Knative Operator installed by default. Knative Operator does not support any configuration of this resource. For example, if you want to add a new label test-label: “test-label” into this resource, how shall we do that? This tutorial will take this resource as an example to give the guidance.

First, create a file named custom-yaml.yaml locally with the content:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: knative-ingress-gateway
namespace: knative-serving
labels:
test-label: "test-label"
serving.knative.dev/release: "v0.24.0"
networking.knative.dev/ingress-provider: istio
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"

Then, create a ConfigMap config-manifest named from this file:

kubectl create configmap config-manifest --from-file=custom-yaml.yaml

If the ConfigMap exists, you can update your ConfigMap with the command:

kubectl create configmap config-manifest --from-file=custom-yaml.yaml -o yaml --dry-run=client | kubectl replace -f -

If you install Knative components with the Knative Operator, you should have a deployment resource named knative-operator in your cluster. Create a file named custom-deploy.json with the content:

{
"spec": {
"template": {
"spec": {
"containers": [{
"name": "knative-operator",
"volumeMounts": [{
"mountPath": "/knative-custom-manifest",
"name": "config-manifest-volume"
}]
}],
"volumes": [{
"name": "config-manifest-volume",
"configMap": {
"name": "config-manifest"
}
}]
}
}
}
}

As you see, the mount path is at /knative-custom-manifest, where you can access the yaml file. Run the command below to patch your deployment of knative-operator:

kubectl patch deployment knative-operator --patch "$(cat custom-deploy.json)"

Now, the deployment knative-operator should be able to access the local volume at the mount path.

You can install Knative Serving with the your customized manifests by applying the following Serving CR:

cat <<-EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: knative-serving
---
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
spec:
version: "0.24"
ingress:
istio:
enabled: true
additionalManifests:
- URL: /knative-custom-manifest
EOF

The field spec.additionalManifests provides you the way to configure the path of the customized manifests. You will see the Gateway resource knative-ingress-gateway is overwritten by the one defined in your yaml file.

Later, if you change your yaml file, you ONLY need to run the following command to update your ConfigMap, so that the change will be reflected in the Knative Operator:

kubectl create configmap config-manifest --from-file=custom-yaml.yaml -o yaml --dry-run=client | kubectl replace -f -

This is how you can leverage the feature of customized manifests to partially update the Knative resource. This feature is the killer for Knative Operator, because it enables you to literally configure anything of Knative with Knative Operator.

Don’t want to derail? Follow Vincent!

--

--

Vincent Hou

A Chinese software engineer, used to study in Belgium and currently working in US, as Knative & Tekton Operator Lead and Istio Operator Contributor.