Config Package
A config package allows the application author to write logic that gets executed by KubeDirector for certain lifecycle events.
The supported lifecycle events are currently:
- configure
- addnodes
- delnodes
Explore an existing config package
To learn about config package, let's explore an application that has defaultConfigPackage
defined.
Open the file: deploy/example_catalog/cr-app-kafka55.json
inside this file we see:
So the appconfig
is embedded in the image in /opt/configscripts/
.
Let's explore that. We can see the image tag is bluedata/kafka:1.0
- download it to your local environment:
Now start the container and login:
The file appconfig/startscript
looks interesting - let's take a closer look.
The startscript begins with:
startscript
is a bash shell script. When a bash shell script is executed command line arguments
are passed to the script are passed in the variables $1
, $2
, etc.
This script is executed by KubeDirector. It is executed for events in a KubeDirector virtual cluster lifecycle, e.g.
- At launch time all pods get
startscript --configure
event - During expansion:
- existing pods get
startscript --addnodes
- new pods get
startscript --configure
- existing pods get
- For shrinking, all nodes get
startscript --delnodes
Create a basic config package
In this section we modify the centos application to log the action inside the container.
previously based on ubuntu
This section initially was based on the ubuntu image, but it appears that image doesn't support appconfig at the moment. See here for more info.
In a terminal, change into the deploy/example_catalog
directory:
Create the directories mycentos
and mycentos/appconfig
:
Inside the appconfig
directory, create a new file named startscript
with the contents:
In the directory /deploy/example_catalog/mycentos
, create a tar file with the appconfig:
Create or update the Dockerfile in the mycentos
directory so that it now contains:
Run a local registry
Check local docker registry is running:
If it is not running, start it with:
Build and Push image
In the terminal, change to the mycentos
folder and build your custom image and push it to the local registry:
Next we push the image to our local registry:
Update the KD app image
Ensure defaultConfigPackage
in the file deploy/example_catalog/cr-app-centos7.json
is set to:
and defaultImageRepoTag
is:
Deploy the KD app image
First ensure you aren't still running an Ubuntu KD clusters from the previous tutorial.
Next undeploy the existing Centos 7 KD application image definition:
Deploy the new Centos KD application with your changes:
Check the deployment was successful:
You can see my image has only just been deployed:
Deploy the KD Cluster
First modify ../../example_clusters/cr-cluster-centos7.yaml
- set memory attributes to 1Gi
.
Next we can deploy the KD Cluster:
You may need to run the above command several times until the Cluster is stable
:
You should see a new pod:
Wait a few seconds and try ls /opt
again - keep trying until you see a guestconfig
folder:
If we cat configure.stdout
we should see the output from our startscript:
Exercise
Exercise 1
Add a node to the cluster by increasing members
from 1
to 2
in the file cr-cluster-centos7.yaml
.
Apply the changes with kubectl apply -f ../../example_clusters/
and use kubectl describe ...
to wait for the changes to finish.
What do you see in the /opt/guestconfig/configure.stdout
for both pods?
Exercise 2
The KD App Role definition has an attribute eventList
.
Delete your KD cluster and modify the eventList in deploy/example_catalog/cr-app-centos7.json
so that your application reacts only to configure
and delnodes
.
Delete and apply the KD application definition for the centos7 app and create a new centos cluster with one member and then increase to two members. Observe the events that are reported in /opt/guestconfig/configure.stdout
.
Reference
- Config Package specification
- Config Python CLI source code
- Config Commands run by KD source code for v0.5.2