Difference between revisions of "Configuring Nexus as a Helm repo"

From ESS-WIKI
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 42: Line 42:
 
To start working on a chart, Helm uses a simple command create:
 
To start working on a chart, Helm uses a simple command create:
  
<syntaxhighlight lang="html4strict">​$ helm create my-app</syntaxhighlight>
 
  
After that Helm creates a directory with the following layout:<span style="background-color: rgb(245, 245, 245); white-space: pre-wrap;">​</span>\
+
<syntaxhighlight lang="html4strict">​$ helm create my-app</syntaxhighlight>After that Helm creates a directory with the following layout:<span style="background-color: rgb(245, 245, 245); white-space: pre-wrap;">​</span>\
  
 
<syntaxhighlight lang="html4strict">my-app/
 
<syntaxhighlight lang="html4strict">my-app/
Line 56: Line 55:
 
│    └── service.yaml
 
│    └── service.yaml
 
└── values.yaml
 
└── values.yaml
2 directories, 7 files</syntaxhighlight>
+
2 directories, 7 files</syntaxhighlight> It has charts directory with chart dependencies, but we don’t need it at the moment. Next comes Chart.yaml containing global variables for the chart such as version and description:
 
 
It has charts directory with chart dependencies, but we don’t need it at the moment. Next comes Chart.yaml containing global variables for the chart such as version and description:
 
  
 
<syntaxhighlight lang="html4strict">​$ cat my-app/Chart.yaml
 
<syntaxhighlight lang="html4strict">​$ cat my-app/Chart.yaml
Line 65: Line 62:
 
description: A Helm chart for Kubernetes
 
description: A Helm chart for Kubernetes
 
name: my-app
 
name: my-app
version: 0.1.0</syntaxhighlight>
+
version: 0.1.0</syntaxhighlight> Then comes templates directory – there you put all the *.yaml files for Kubernetes. Helm uses Go template markup language to customize these files. Helm creates three default file types: deployment, service, and ingress. All the files in this directory are ‘skeletons’ which are filled with the variables from values.yaml when you deploy your Helm chart. File _helpers.tpl contains your custom helper functions for variable calculation. By default, helm creates an nginx deployment. Let’s customize it a bit. Add new ConfigMap to the templates directory:
 
 
Then comes templates directory – there you put all the *.yaml files for Kubernetes. Helm uses Go template markup language to customize these files. Helm creates three default file types: deployment, service, and ingress. All the files in this directory are ‘skeletons’ which are filled with the variables from values.yaml when you deploy your Helm chart. File _helpers.tpl contains your custom helper functions for variable calculation. By default, helm creates an nginx deployment. Let’s customize it a bit. Add new ConfigMap to the templates directory:
 
  
<syntaxhighlight lang="html4strict">​$ cat << HELM &gt; my-app/templates/cm.yaml
+
<syntaxhighlight lang="html4strict">​$ cat << HELM > my-app/templates/cm.yaml
 
apiVersion: v1
 
apiVersion: v1
 
data:
 
data:
Line 80: Line 75:
 
       listen 80;
 
       listen 80;
 
       location / {
 
       location / {
         return 200 "===============================\n\n &nbsp;&nbsp;This is your helm deploy! \n\n===============================\n";
+
         return 200 "===============================\n\n This is your helm deploy! \n\n===============================\n";
 
       }
 
       }
 
     }
 
     }
Line 88: Line 83:
 
name: nginx-config
 
name: nginx-config
 
HELM
 
HELM
</syntaxhighlight>
+
</syntaxhighlight> Point our nginx Deployment to that ConfigMap. Add the following lines to the deployment.yaml:
 
 
Point our nginx Deployment to that ConfigMap. Add the following lines to the deployment.yaml:
 
  
 
<syntaxhighlight lang="html4strict">volumes: 
 
<syntaxhighlight lang="html4strict">volumes: 
Line 96: Line 89:
 
   configMap:
 
   configMap:
 
     name: nginx-config
 
     name: nginx-config
</syntaxhighlight>
+
</syntaxhighlight> and:
 
 
and:
 
  
 
<syntaxhighlight lang="html4strict">volumeMounts:
 
<syntaxhighlight lang="html4strict">volumeMounts:
Line 104: Line 95:
 
   mountPath: /etc/nginx/nginx.conf
 
   mountPath: /etc/nginx/nginx.conf
 
   subPath: nginx.conf
 
   subPath: nginx.conf
</syntaxhighlight>  
+
</syntaxhighlight> That’s it! Let’s check if we are doing the right thing: helm template my-app This will generate all templates with variables and show the output. Now that we know everything is OK, we can deploy the chart:
 
 
That’s it! Let’s check if we are doing the right thing: helm template my-app This will generate all templates with variables and show the output. Now that we know everything is OK, we can deploy the chart:
 
 
 
<syntaxhighlight lang="html4strict">helm install my-app --name=my-app-name</syntaxhighlight>
 
  
Then check that Service and Deploy have been created and curl our Service:
+
<syntaxhighlight lang="html4strict">helm install my-app --name=my-app-name</syntaxhighlight> Then check that Service and Deploy have been created and curl our Service:
  
 
<syntaxhighlight lang="html4strict">$ kubectl get svc
 
<syntaxhighlight lang="html4strict">$ kubectl get svc
Line 120: Line 107:
 
  This is your helm deploy!
 
  This is your helm deploy!
 
====== =================== ======
 
====== =================== ======
</syntaxhighlight>
+
</syntaxhighlight> Congratulations! We have created and deployed our first Helm chart. Additionally, you can create a package:
 +
 
 +
<syntaxhighlight lang="html4strict">$ helm package my-app</syntaxhighlight> This command creates an archive like my-app-0.1.0.tgz — now you can share your chart with others. For instance, you can upload this file to Helm repository, which we are going to do now.
 +
 
 +
== '''Upload HELM Package''' ==
 +
 
 +
Upload the tgz file at Upload/helm-private page.
 +
 
 +
[[File:Upload Helm package.png|640x286px|Upload Helm package.png]]
 +
 
 +
The upload package is shown below.
 +
 
 +
[[File:HelmPackage.png|388x197px|HelmPackage.png]]
 +
 
 +
== '''Check on private helm''' ==
 +
 
 +
Check the repo list
 +
 
 +
[[File:Helm repo list.png|800x134px]]
  
Congratulations! We have created and deployed our first Helm chart.
+
Search on private helm
  
Additionally, you can create a package:
+
[[File:Helm search.png|800x62px]]
  
<syntaxhighlight lang="html4strict">$ helm package my-app</syntaxhighlight>
+
= '''Reference''' =
  
This command creates an archive like my-app-0.1.0.tgz — now you can share your chart with others. For instance, you can upload this file to Helm repository, which we are going to do now.
+
*'''[https://medium.com/containerum/how-to-make-and-share-your-own-helm-package-50ae40f6c221 https://medium.com/containerum/how-to-make-and-share-your-own-helm-package-50ae40f6c221]'''

Latest revision as of 11:08, 22 October 2018

What we will do:

– create a private (hosted) repository for our own package

– create a proxy repository pointing to stable helm repo server (https://kubernetes-charts.storage.googleapis.com) for 'kubernetes'or other private repo.

I suggest you create a new blob store for each new repo you want to create. That way, the data for every repo will be in a different folder in /nexus-data.

But this is not mandatory for it to work.

private repo

A repository for Helm repo that your team creates.

Create a new Helm (hosted) repository and configure it like:

Helm-private.png

proxy repo

A repository that proxies everything you download from the official repository, Kubeapps Hub. Next time you download the same dependency, it will be cached in your Nexus.

Create a new Helm (proxy) repository and configure it like:

Helm-proxy.png


Configuring Helm for private repository

Configuring Helm to use Nexus Repository is fairly easy! Once you have Helm up and running you'll want to run a command similar to the following:


​$ helm repo add nexusrepo http://localhost:8081/repository/helm-proxy/
Replace nexusrepo with what you'd like the repo to be called, and the url with what the full url to your proxy repository is. From that point you can install helm charts using a command similar to the following:
​$ helm install nexusrepo/mongodb
If everything went smoothly, the command above will install the latest version of mongodb.

Create a package

What is a helm chart? It is basically a set of templates and a file containing variables used to fill these templates. Let’s have a look at an example. I assume that you already have Helm installed and configured at this point.

To start working on a chart, Helm uses a simple command create:


​$ helm create my-app
After that Helm creates a directory with the following layout:\
my-app/
├── charts
├── Chart.yaml
├── templates
│     ├── deployment.yaml
│     ├── _helpers.tpl
│     ├── ingress.yaml
│     ├── NOTES.txt
│     └── service.yaml
└── values.yaml
2 directories, 7 files
It has charts directory with chart dependencies, but we don’t need it at the moment. Next comes Chart.yaml containing global variables for the chart such as version and description:
​$ cat my-app/Chart.yaml
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: my-app
version: 0.1.0
Then comes templates directory – there you put all the *.yaml files for Kubernetes. Helm uses Go template markup language to customize these files. Helm creates three default file types: deployment, service, and ingress. All the files in this directory are ‘skeletons’ which are filled with the variables from values.yaml when you deploy your Helm chart. File _helpers.tpl contains your custom helper functions for variable calculation. By default, helm creates an nginx deployment. Let’s customize it a bit. Add new ConfigMap to the templates directory:
​$ cat << HELM > my-app/templates/cm.yaml
apiVersion: v1
data:
nginx.conf: |
  events {
    worker_connections 1024;
  }
  http {
    server {
      listen 80;
      location / {
        return 200 "===============================\n\n  This is your helm deploy! \n\n===============================\n";
      }
    }
  }
kind: ConfigMap
metadata:
name: nginx-config
HELM
Point our nginx Deployment to that ConfigMap. Add the following lines to the deployment.yaml:
volumes: 
- name: config
  configMap:
    name: nginx-config
and:
volumeMounts:
- name: config
  mountPath: /etc/nginx/nginx.conf
  subPath: nginx.conf
That’s it! Let’s check if we are doing the right thing: helm template my-app This will generate all templates with variables and show the output. Now that we know everything is OK, we can deploy the chart:
helm install my-app --name=my-app-name
Then check that Service and Deploy have been created and curl our Service:
$ kubectl get svc
NAME                         TYPE CLUSTER-IP EXTERNAL-IP  PORT(S) AGE
my-app-name-my-app      ClusterIP 10.100.56.254 <none>     80/TCP 44m

$ curl 10.100.56.254
====== =================== ======
 This is your helm deploy!
====== =================== ======
Congratulations! We have created and deployed our first Helm chart. Additionally, you can create a package:
$ helm package my-app
This command creates an archive like my-app-0.1.0.tgz — now you can share your chart with others. For instance, you can upload this file to Helm repository, which we are going to do now.

Upload HELM Package

Upload the tgz file at Upload/helm-private page.

Upload Helm package.png

The upload package is shown below.

HelmPackage.png

Check on private helm

Check the repo list

Helm repo list.png

Search on private helm

Helm search.png

Reference