Deploy Package on a cluster
7 minute read
You can install artifacts in your cluster in several ways. When creating a package, you can use one of the following plugins:
- helm
- kubectl
- cmd
- kosi
This guide demonstrates a complete, reproducible deployment of nginx-ingress using Helm and kosi.
Using the Helm Plugin
Pre-requisites
Before you begin, make sure the following tools are available in your environment:
helmkosi
This example uses the official NGINX Helm repository and deploys nginx-ingress with Helm and KOSI.
Prepare the Files
In order to install an artifact with the Helm plugin, the Helm chart must first be downloaded.
To keep the environment clean and reproducible, first create a dedicated working directory and change into it:
mkdir nginx-ingress-kosi && cd nginx-ingress-kosi
The example uses the official NGINX Helm repository. Add the repository before performing any Helm operations:
helm repo add nginx-stable https://helm.nginx.com/stable
helm repo update
To verify which chart versions are available, run:
helm search repo nginx-stable/nginx-ingress --versions
This guide uses chart version 0.16.1. Download the chart as a packaged Helm artifact:
helm pull nginx-stable/nginx-ingress --version 0.16.1
This command creates the following file in your working directory:
nginx-ingress-0.16.1.tgz
Create KOSI package
Once the chart is available locally, initialize the kosi package structure. The following command creates the necessary files in the current directory:
kosi create
The Helm chart remains the central input artifact for deployment, while configuration is handled via values.yaml. Helm already includes default values, which can be inspected or exported if needed:
helm show values nginx-stable/nginx-ingress --version 0.16.1 > values.yaml
Review and update values.yaml before packaging and deploying the chart. For example, in environments without a cloud-based LoadBalancer, you may need to change the service type in values.yaml.
controller:
service:
type: LoadBalancer
Only required overrides should be defined in the customized values.yaml file. To customize the deployment of the Helm chart, a new values.yaml file in the current directory must be created and edited with this content:
controller:
service:
type: NodePort
This override is merged with the chart defaults at runtime.
Helm charts do not directly contain the full list of container images required for deployment. To identify them, render the chart into Kubernetes manifests:
helm template nginx-ingress nginx-stable/nginx-ingress --version 0.16.1 > manifests.yaml
Then extract all referenced images from the rendered manifest:
grep image: manifests.yaml
For this example, the required image is:
nginx/nginx-ingress:3.0.1
With all artifacts identified, the package.kosi file defines what is required for deployment. It explicitly references:
- the Helm chart archive
- the custom values.yaml
- all required container images
nginx-ingress-0.16.1.tgz
values.yaml
package.kosi
- The downloaded Helm chart must also be located in the current directory. To customize the deployment of the Helm chart, the
values.yamlfile must be edited.
All files required by a task in the package must be named in the package.kosi file under files. The container images required by the Helm chart must also be listed in the package.kosi under containers.
In the example below, only two files are required for the installation: the Helm Chart for the nginx-ingress and the values.yaml to configure the deployment. To install nginx-ingress you will also need the nginx/nginx-ingress image with the tag 3.0.1.
To install nginx-ingress with the Helm plugin, call the plugin as shown in the example under install. The deployment configuration file is listed under values and the packed Helm chart is specified with the key tgz. Furthermore, it is also possible to specify the namespace in which the artifact should be deployed and the name of the deployment. The full documentation for the Helm plugin can be found here.
Use the following configuration:
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "deployexample1";
description = "It shows how to deploy an artifact to your cluster using the helm plugin.";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
valuesFile = "values.yaml";
nginxHelmChart="nginx-ingress-0.16.1.tgz";
}
containers =
{
nginx = ["docker.io", "nginx/nginx-ingress", "3.0.1"];
}
install
{
helm
(
command = "install";
tgz = "nginx-ingress-0.16.1.tgz";
values = "['values.yaml']";
namespace = "dev";
deploymentName = "nginx-ingress"
);
}
Build the Package
Once the package.kosi file has been fully configured, all files must be combined into a kosi package. To do this, execute the following command in the directory where the package.kosi file is located.
kosi build
Push the Package
To make the generated kosi package available on other machines, it is pushed to the user’s private KubeOps Hub. To do this, the user must first log in to the hub and then push it to hub.
$ kosi login -u <username>
2023-02-04 11:19:43 Info: KOSI version: 2.13.0_Alpha0
2023-02-04 11:19:43 Info: Please enter password
****************
2023-02-04 11:19:26 Info: Login Succeeded to Hub.
$ kosi push --hub kosi
2023-02-04 11:23:18 Info: KOSI version: 2.13.0_Alpha0
2023-02-04 11:23:19 Info: Push to Private Registry registry.preprod.kubeops.net/<username>/
Deploy the Package
Once the KOSI package has been created and published, it needs to be installed on the admin node. The following command will download and execute the package. The package name and version refer to the values defined in package.kosi with the keys name and version.
kosi install --hub <username> <username>/<packagename>:<version>
For the example package, the command would be: kosi install --hub <username> <username>/deployExample:0.1.0.
Using the Kubectl Plugin
Prerequisites
Before you begin, make sure the following tools and components are available:
- kosi
- the
kubeops-kubernetes-pluginspackage installed on the admin node
This example deploys nginx-ingress from a Kubernetes manifest using the Kubectl plugin.
Create KOSI package
First you need to create a KOSI package. The following command creates the necessary files in the current directory:
kosi create
The NGINX ingress controller YAML manifest can either be automatically downloaded and applied directly with kubectl apply or it can be downloaded manually if you want to customize the deployment. The YAML manifest can be downloaded from the NGINX GitHub Repo and must be placed in the same directory as the files for the KOSI package.
All files required by a task in the package must be named in the package.kosi file under files. The container images required by the YAML manifest must also be listed in the package.kosi under containers.
In the example below, only one file is required for the installation: the YAML manifest for the nginx-ingress controller. To install nginx-ingress you will also need the registry.k8s.io/ingress-nginx/controller image with the tag v1.5.1 and the image registry.k8s.io/ingress-nginx/kube-webhook-certgen with tag v20220916-gd32f8c343.
To install nginx-ingress with the Kubectl plugin, call the plugin as shown in the example under installs. The full documentation for the Kubectl plugin can be found here.
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "deployexample2";
description = "It shows how to deploy an artifact to your cluster using the helm plugin.";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
manifest: "deploy.yaml"
}
containers =
{
nginx = ["registry.k8s.io", "ingress-nginx/controller", "v1.5.1"];
certgen= ["registry.k8s.io","ingress-nginx/kube-webhook-certgen","v20220916-gd32f8c343"];
}
install
{
kubectl
(
operation="apply",
flags="-f deploy.yaml";
sudo = true;
sudoPassword="toor"
);
}
Build the Package
Once the package.kosi file has been fully configured, all files must be combined into a KOSI package. To do this, execute the following command in the directory where the package.kosi file is located.
kosi build
Publish the Package
To make the generated KOSI package available on other machines, it is pushed to the user’s private KubeOps Hub. To do this, the user must first log in to the hub.
$ kosi login -u <username>
2023-02-04 11:19:43 Info: kosi version: 2.13.0_Alpha0
2023-02-04 11:19:43 Info: Please enter password
****************
2023-02-04 11:19:26 Info: Login Succeeded to Hub.
$ kosi push --hub kosi
2023-02-04 11:23:18 Info: kosi version: 2.13.0_Alpha0
2023-02-04 11:23:19 Info: Push to Private Registry registry.preprod.kubeops.net/<username>/
Deploy the Package
Once the KOSI package has been created and published, it needs to be installed on the admin node. The following command will download and execute the package. The package name and version refer to the values defined in package.kosi with the keys name and version.
kosi install --hub <username> <username>/<packagename>:<version>
For the example package, the command would be: kosi install --hub <username> <username>/deployExample:0.1.0.