CDAP Kubernetes Operator
Alpha
The CDAP Operator is still under active development and has not been extensively tested in production environment. Backward compatibility of the APIs is not guaranteed for alpha releases.
You can checkout the CDAP Operator source code, build and run locally. To build the CDAP Operator, you need to setup your environment for the Go language. Also, you should have a Kubernetes cluster
mkdir -p $GOPATH/src/cdap.io
cd $GOPATH/src/cdap.io
git clone https://github.com/cdapio/cdap-operator.git
cd cdap-operator
make install
make run
kubectl apply -k config/crd
kubectl apply -f config/samples/cdap_v1alpha1_cdapmaster.yaml
You can also build a docker image containing the CDAP controller and deploy it to Kubernetes.
You can change the target image name and tag by setting the
IMG=cdap-controller:latest make docker-build
IMG
environment variable.
IMG=cdap-controller:latest make docker-push
make deploy
A step by step guide of running CDAP in Kubernetes using CDAP operator can be found in the blog post.
The CDAP operator can be configured to optionally run a webhook server for a mutating admission controller. The mutating admission controller allows the operator to change the following fields in CDAP pods:
These mutations can be defined using the MutationConfigs
field in CDAPMaster.
Kubernetes requires that the webhook server uses TLS to authenticate with the kube API server. For this you will need to ensure the TLS certificates are present in the /tmp/k8s-webhook-server/serving-certs
directory in the cdap-controller
pod. To simplify the management of TLS certificates, you can use cert-manager. The following steps assume you are in the root directory of the Git repository and have already deployed the CDAP operator stateful set.
You should see 3 pods running for cert-manager.
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml
kubectl get pods -n cert-manager
NAME READY STATUS RESTARTS AGE
cert-manager-655c4cf99d-rbzwr 1/1 Running 0 2m
cert-manager-cainjector-845856c584-csbsw 1/1 Running 0 2m
cert-manager-webhook-57876b9fd-68vgc 1/1 Running 0 2m
# set the namespace in which CDAPMaster is deployed.
export CDAP_NAMESPACE=default
sed -e 's@{CDAP_NAMESPACE}@'"$CDAP_NAMESPACE"'@g' <"./webhooks/templates/webhook-service.yaml" | kubectl apply -f -
sed -e 's@{CDAP_NAMESPACE}@'"$CDAP_NAMESPACE"'@g' <"./webhooks/templates/issuer.yaml" | kubectl apply -f -
Wait for the certificate to be ready.
sed -e 's@{CDAP_NAMESPACE}@'"$CDAP_NAMESPACE"'@g' <"./webhooks/templates/certificate.yaml" | kubectl apply -f -
kubectl get Certificates
NAME READY SECRET AGE
cdap-webhook-cert True cdap-webhook-server-cert 1d
6. Deploy the mutating webhook resource:
```bash
sed -e 's@{CDAP_NAMESPACE}@'"$CDAP_NAMESPACE"'@g' <"./webhooks/templates/webhook.yaml" | kubectl apply -f -
The webhook is now configured and it will intercept requests to create new pods made by CDAP.
Assuming task workers are enabled, the pods that execute user code in CDAP are task workers and preview runners. Let us call these pods as “worker pods”. To isolate these worker pods in a dedicated node pool with the help of the admission controller, you follow these steps:
gcloud container node-pools create worker-pool \
--cluster cdap-cluster --project my-gcp-projet --location us-east1
gcloud beta container node-pools update worker-pool \
--node-taints="worker-pods-only=true:NoExecute" \
--cluster cdap-cluster --project my-gcp-projet --location us-east1
Add the following configuration to the CDAPMaster:
# Filename: cdapmaster.yaml
spec:
...
mutationConfigs:
- labelSelector:
matchExpressions:
- {key: cdap.twill.app, operator: In, values: [task.worker, preview.runner]}
podMutations:
nodeSelectors:
cloud.google.com/gke-nodepool: worker-pool
tolerations:
- effect: NoExecute
key: worker-pods-only
operator: Equal
tolerationSeconds: 3600
value: "true"
Now whenever CDAP launches preview runner of task worker pods, the admission controller will mutate the pod specifications before they are deployed to ensure the pods get scheduled only on the node pool “worker-pool”.
Install kubebuilder.
Install setup-envtest by running:
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
After installing setup-envtest
, use it to download envtest 1.19.x for kubebuilder and to set your KUBEBUILDER_ASSETS environment variable:
# Downloads envtest v1.19.x and writes the export statement to a temporary file
$(go env GOPATH)/bin/setup-envtest use -p env 1.19.x > /tmp/setup_envtest.sh
# Sets the KUBEBUILDER_ASSETS environment variable
source /tmp/setup_envtest.sh
# Deletes the temporary file
rm /tmp/setup_envtest.sh
Run make test