Install Kubebuilder and then bootstrap the At
operator as follows:
$ mkdir cnat-kubebuilder && cd $_
$ kubebuilder init \
--domain programming-kubernetes.info \
--license apache2 \
--owner "We, the Kube people"
$ kubebuilder create api \
--group cnat \
--version v1alpha1 \
--kind At
Create Resource under pkg/apis [y/n]?
y
Create Controller under pkg/controller [y/n]?
y
...
# install CRD via:
$ make install
# create the dedicated namespace and set the context to it:
$ kubectl create ns cnat && \
kubectl config set-context $(kubectl config current-context) --namespace=cnat
# launch operator:
$ make run
Now, once we create the At
custom resource, we see the execution at the scheduled time:
$ kubectl apply -f config/samples/cnat_v1alpha1_at.yaml
$ kubectl -n cnat get at,po
NAME AGE
at.cnat.programming-kubernetes.info/example-at 54s
NAME READY STATUS RESTARTS AGE
pod/example-at-pod 0/1 Completed 0 32s
- In at_types.go: we modify the
AtSpec
struct to include the respective fields such asschedule
andcommand
. Note that you must runmake
whenever you change something here in order to regenerate the controller code. - In at_controller.go: we modify the
Reconcile(request reconcile.Request)
method to create a pod at the time defined inSpec.Schedule
.