The following steps setup a development Kubernetes to test the operator locally. In this walk-through, we are going to use minikube.
- Minikube Installation
- kubectl (or use the one bundled with minikube bundled with minikube
alias kubectl="minikube kubectl --"
) - optional:
operator-sdk
As the first step, we need to make sure the cluster is up and running:
minikube start
Run the operator:
# configure crd
make install
# run the operator locally
make run
Create Mondoo Secret
and add the MondooAuditConfig
:
kubectl create namespace mondoo-operator
kubectl create secret generic mondoo-client --namespace mondoo-operator --from-file=config=creds.json
kubectl apply -f config/samples/k8s_v1alpha2_mondooauditconfig_minimal.yaml
As preparation you need to build the operator container image for deployment in Kubernetes. This ensures that the latest image is available in the cluster.
make load-minikube
Next let us deploy the operator application:
make deploy
# Or if you want to deploy using OLM
make deploy-olm
NOTE: deploy target uses
kubectl
under the cover, therefore make sure kubectl is configured to use minikube NOTE: deploy-olm target uses operator-sdk and depends on olm being installed
Now, we completed the setup for the operator. To start the service, we need to configure the client:
- Create namespace using
kubectl create namespace mondoo-operator
- Configure the Mondoo secret:
- Create a new Mondoo service account to report assessments to Mondoo Platform
- Store the service account json into a local file
creds.json
- Store service account as a secret in the mondoo namespace via:
kubectl create secret generic mondoo-client --namespace mondoo-operator --from-file=config=creds.json
- Update SecretName created in step 4 in the mondoo-client CRD.
Then apply the configuration:
kubectl apply -f config/samples/k8s_v1alpha2_mondooauditconfig_minimal.yaml
Validate that everything is running:
kubectl get pods --namespace mondoo-operator
NAME READY STATUS RESTARTS AGE
mondoo-client-hjt8z 1/1 Running 0 16m
mondoo-operator-controller-manager-556c7d4b56-qqsqh 2/2 Running 0 88m
To delete the client configuration, run:
kubectl delete -f config/samples/k8s_v1alpha2_mondooauditconfig_minimal.yaml
I do not see the service running, only the operator?
First check that the CRD is properly registered with the operator:
kubectl get crd
NAME CREATED AT
mondooauditconfigs.k8s.mondoo.com 2022-01-14T14:07:28Z
Then make sure a configuration for the Mondoo Client is deployed:
kubectl get mondooauditconfigs
NAME AGE
mondooauditconfig-sample 2m44s