The focus of this lab is to become familar with KUDO. Through this lab you hand craft an operator, create an operator repository and install the operator to your kubernetes cluster.
- Running Kubernetes 1.15+ cluster
This is a step-by-step walk through of the creation of an operator using the KUDO CLI to generate the KUDO operator structure.
# create operator folder
mkdir first-operator
cd first-operator
kubectl kudo package new first-operator
This creates the main structure of the operator which can be viewed using the tree
command:
$ tree .
.
└── operator
├── operator.yaml
└── params.yaml
::: tip Note
Use the -i
flag with kubectl kudo package new
to be prompted interactively for operator details.
:::
kubectl kudo package add maintainer "your name" [email protected]
kubectl kudo package add task
This command uses an interactive prompt to construct the details of the task. Here is an example interaction:
$ kubectl kudo package add task
Task Name: app
✔ Apply
Task Resource: deployment
✗ Add another Resource:
kubectl kudo package add plan
This command uses an interactive prompt to construct the details of the plan. Here is an example interaction:
$ kubectl kudo package add plan
✔ Plan Name: deploy
✔ serial
Phase 1 name: main
✔ parallel
Step 1 name: everything
✔ app
✗ Add another Task:
✗ Add another Step:
✗ Add another Phase:
kubectl kudo package add parameter
This command uses an interactive prompt to construct the details of the parameter. Here is an example interaction:
$ kubectl kudo package add parameter
Parameter Name: replicas
Default Value: 2
Display Name:
Description: Number of replicas that should be run as part of the deployment
✔ false
✗ Add Trigger Plan:
These steps have created the entirety of the first-operator with the exception of the details in the template/deployment.yaml
file. To complete this operator execute the following:
cat << EOF > operator/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: {{ .Params.replicas }}
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
In order to distribute a KUDO operator the files are packaged together in a compressed tarball. The KUDO CLI provides a mechanism to create this package format while verifying the integrity of the operator.
rm -rf ~/repo
mkdir -p ~/repo
kubectl kudo package create repository/first-operator/operator/ --destination=~/repo
::: warning Potential Data Loss
You may want to check the contents of the ~/repo
folder prior to deleting it.
:::
The output looks like:
kubectl kudo package create repository/first-operator/operator/ --destination=~/repo
package is valid
Package created: /Users/kensipe/repo/first-operator-0.2.0.tgz
ls ~/repo
first-operator-0.2.0.tgz
The objective of this lab is to initialize KUDO in a Kubernetes cluster.
kubectl kudo init --wait
This results in:
- the deployment of KUDO CRDs
- the creation of kudo-system namespace
- deployment of the kudo controller
Output of a KUDO init will look like the following:
$ kubectl kudo init
✅ installed crds
✅ installed service accounts and other requirements for controller to run
✅ installed kudo controller
The installation of KUDO is verified by confirming that the kudo-controller-manager-0
is in a running status.
$ kubectl get -n kudo-system pod
NAME READY STATUS RESTARTS AGE
kudo-controller-manager-0 1/1 Running 0 11m
This lab explains how to host an operator repository on your local system.
kubectl kudo repo index ~/repo
cd ~/repo
python -m http.server 80
kubectl kudo repo add local http://localhost
kubectl kudo repo context local
$ kubectl kudo repo list
NAME URL
community https://kudo-repository.storage.googleapis.com/0.10.0
*local http://localhost
::: tip Note
The *
next to local indicates that it is the default context for the KUDO client.
:::
Using the verbose CLI output flag (-v
) with KUDO it is possible to trace from where an operator is being installed from.
kubectl kudo install first-operator -v 9
The output should look like:
$ kubectl kudo install first-operator -v 9
repo configs: { name:community, url:https://kudo-repository.storage.googleapis.com/0.10.0 },{ name:local, url:http://localhost }
repository used { name:local, url:http://localhost }
configuration from "/Users/kensipe/.kube/config" finds host https://127.0.0.1:32768
acquiring kudo client
getting package crds
no local operator discovered, looking for http
no http discovered, looking for repository
getting package reader for first-operator, _
repository using: { name:local, url:http://localhost }
attempt to retrieve package from url: http://localhost/first-operator-0.2.0.tgz
first-operator is a repository package from { name:local, url:http://localhost }
operator name: first-operator
operator version: 0.2.0
parameters in use: map[]
operator.kudo.dev/first-operator unchanged
instance first-operator-instance created in namespace default
instance.kudo.dev/v1beta1/first-operator-instance created
You will also see in the terminal running python http.server the following:
127.0.0.1 - - [14/Jan/2020 07:59:24] "GET /index.yaml HTTP/1.1" 200 -
127.0.0.1 - - [14/Jan/2020 07:59:24] "GET /first-operator-0.2.0.tgz HTTP/1.1" 200 -