Creating Helm Charts

Our next goal is to create a Chart for the go-demo-3 application. We'll use the fork, you created in the previous chapter.

First, we'll move into the fork's directory.

 1  cd ../go-demo-3

To be on the safe side, we'll push the changes you might have made in the previous chapter and then we'll sync your fork with the upstream repository. That way we'll guarantee that you have all the changes I might have made.

You probably already know how to push your changes and how to sync with the upstream repository. In case you don't, the commands are as follows.

 1  git add .
 2
 3  git commit -m 
 4      "Defining Continuous Deployment chapter"
 5
 6  git push
 7
 8  git remote add upstream 
 9      https://github.com/vfarcic/go-demo-3.git
10
11  git fetch upstream
12
13  git checkout master
14
15  git merge upstream/master

We pushed the changes we made in the previous chapter, we fetched the upstream repository vfarcic/go-demo-3, and we merged the latest code from it. Now we are ready to create our first Chart.

Even though we could create a Chart from scratch by creating a specific folder structure and the required files, we'll take a shortcut and create a sample Chart that can be modified later to suit our needs.

We won't start with a Chart for the go-demo-3 application. Instead, we'll create a creatively named Chart my-app that we'll use to get a basic understanding of the commands we can use to create and manage our Charts. Once we're familiar with the process, we'll switch to go-demo-3.

Here we go.

 1  helm create my-app
 2
 3  ls -1 my-app

The first command created a Chart named my-app, and the second listed the files and the directories that form the new Chart.

The output of the latter command is as follows.

Chart.yaml
charts
templates
values.yaml

We will not go into the details behind each of those files and directories just yet. For now, just note that a Chart consists of files and directories that follow certain naming conventions.

If our Chart has dependencies, we could download them with the dependency update command.

 1  helm dependency update my-app

The output shows that no requirements were found in .../go-demo-3/my-app/charts. That makes sense because we did not yet declare any dependencies.

For now, just remember that they can be downloaded or updated. Once we're done with defining the Chart of an application, we can package it.

 1  helm package my-app

We can see from the output that Helm successfully packaged chart and saved it to: .../go-demo-3/my-app-0.1.0.tgz. We do not yet have a repository for our Charts. We'll work on that in the next chapter.

If we are unsure whether we made a mistake in our Chart, we can validate it by executing lint command.

 1  helm lint my-app

The output is as follows.

==> Linting my-app
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, no failures

We can see that our Chart contains no failures, at least not those based on syntax. That should come as no surprise since we did not even modify the sample Chart Helm created for us.

Charts can be installed using a Chart repository (for example, stable/jenkins), a local Chart archive (for example, my-app-0.1.0.tgz), an unpacked Chart directory (for example, my-app), or a full URL. So far, we used Chart repository to install Jenkins. We'll switch to the local archive option to install my-app.

 1  helm install ./my-app-0.1.0.tgz 
 2    --name my-app

The output is as follows.

NAME:   my-app
LAST DEPLOYED: Thu May 24 13:43:17 2018
NAMESPACE: default
STATUS: DEPLOYED
    
RESOURCES:
==> v1/Service
NAME   TYPE      CLUSTER-IP     EXTERNAL-IP PORT(S) AGE
my-app ClusterIP 100.65.227.236 <none>      80/TCP  1s
    
==> v1beta2/Deployment
NAME   DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
my-app 1       1       1          0         1s
    
==> v1/Pod(related)
NAME                    READY STATUS            RESTARTS AGE
my-app-7f4d66bf86-dns28 0/1 ContainerCreating 0 1s

NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app=my-app,release=my-app" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80

The sample application is a straightforward one with a Service and a Deployment. There's not much to say about it. We used it only to explore the basic commands for creating and managing Charts. We'll delete everything we did and start over with a more serious example.

 1  helm delete my-app --purge
2 3 rm -rf my-app
4
5 rm -rf my-app-0.1.0.tgz

We deleted the Chart from the cluster, as well as the local directory and the archive we created earlier. The time has come to apply the knowledge we obtained and explore the format of the files that constitute a chart. We'll switch to the go-demo-3 application next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.245.1