kctrl
In this tutorial, we will see how to create a package from Kuberenetes manifest present in a Git repository. We will again use MongoDb enterprise operator as an example here.
MongoDb enterprise operator
Github Repository mentions that crds.yaml
and mongodb-enterprise.yaml
are the Kubernetes resources which can be installed directly to the cluster to make the operator available. We will package crds.yaml
and mongodb-enterprise.yaml
into a Carvel package and make it available for distribution.To initialize, we will use kctrl pkg init
.
This command asks a few basic questions regarding how we want to initialize our package. Lets go through them together:
> Enter the package reference name (samplepackage.corp.com):
mongodb-operator.carvel.dev
as our package name.> Enter source (1):
repo
. Hence, we will select Option 4
.> Enter Git URL ():
https://github.com/mongodb/mongodb-enterprise-kubernetes
.> Enter Git Reference (origin/main):
1.17.2
.> Enter the paths which contain Kubernetes manifests ():
crds.yaml,mongodb-enterprise.yaml
After entering all the above details, vendir
will download the helm chart locally into upstream
folder. kctrl
will generate two files - package-build.yml and pacakge-resources.yml as output. Package-resources.yml
file contain Package, PackageInstall and PackageMetadata while package-build.yml
contains PackageBuild. All the values entered above have been recorded in these files. These files will be used by the dev
and pkg release
command subsequently.
kctrl pkg release
will be used to release the package.
This command will create an imgpkg bundle, upload it to the OCI registry, create package.yml
and metadata.yml
which can be released for consumption eventually. Also, we are versioning our package with -v
flag.
> Enter the registry URL ():
docker.io/rohitagg2020/mongodb-operator-bundle
to docker.io/<YOUR_DOCKERHUB_ACCOUNT>/mongodb-operator-bundle
. Alternatively, you can enter other valid OCI registry URL.Now, we have created our Package and PackageMetadata.
Let's see how the Package and PackageMetadata files look like:
Next step is to add it to package repository.
These files can be submitted to the version control tools like github, etc. so that next time while running pkg init
or pkg release
, these values can be picked up as default values.
kctrl
can be used to release packages grouped together into a PackageRepository
. Letβs bundle the dynatrace
package created above into the PackageRepository.
We will reuse the package repository which was created in tutorial-2
kctrl
will create a repo bundle from all the packages and metadata present in the packages
folder.
We will copy the package.yml
and metadata.yml
created above into the packages
folder. We will follow the bundle format as mentioned here. Alternatively, while running pkg release
, --repo-output
flag can be used to copy the package.yml
and metadata.yml
in the prescribed PackageRepository bundle format at a specified location.
Now, we will run kctrl pkg repo release
to create and release the repository bundle. This repository bundle can be distributed to the the package consumer.
In this command, it will ask for package repository name and where to push our repository bundle. Also, we are versioning our package repository with -v
flag.
> Enter the package repository name (sample-repo.carvel.dev):
demo-repo.carvel.dev
as our package repository name.> Enter the registry url ():
packages
and metadata
yaml files present in the packages
folder will be bundled into imgpkg bundle
and then pushed to the above registry url. While entering the registry URL, ensure to change the value from docker.io/rohitagg2020/demo-repo-bundle
to docker.io/<YOUR_DOCKERHUB_ACCOUNT>/demo-repo-bundle
. Alternatively, you can enter other valid OCI registry URL.To test the package, we will again use kctrl.
First step is to add the packageRepository to the Kubernetes cluster by using kctrl pkg repo add
command. Once the package repository is added, all the packages in that repository becomes available to install.
Then we can install a package by using kctrl pkg install
command.
Since package repository and package install are custom resources(CRs), we have to deploy the kapp-controller
onto the cluster so that all these CRs become available on the cluster.
NOTE: In case you have already installed kapp-controller
, skip this section.
To install, kapp-controller
, run
To add the package repo, we will run
To list the available packages, run
To install the package, we will run
To confirm that package has been installed successfully, list down the pods and ensure that mongodb-operator
has been deployed successfully.
$ kubectl get pods -n kctrl-test