To get started, it's necessary to create your cluster on Google Cloud. Once you get your cluster created, we can now create our html page that will be our "application".
Creating and Pushing the docker image
Let's create a HTML page and publish it to a docker image.
mkdir simple-app
cd simple-app
touch index.html
vim index.html
The Dockerfile would be something really simple, for example:
FROM nginx:alpine
COPY . /usr/share/nginx/html
The docker image should be in a Docker Registry .
Using helm
If you never used helm, it helps you deploy and manage your kubernetes applications. In this tutorial, helm will be used to kick start our kubernetes deployment.
You should install helm first.
helm create simple-app
This will create all the files from helm.
.
├── Chart.yaml
├── charts
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── ingress.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
Let’s open the file
values.yaml
. We need to point the repository to our container registry URL, and also the tag.
image:
repository: <YOUR CONTAINER REGISTRY GOES HERE>
tag: <YOUR TAG GOES HERE>
pullPolicy:IfNotPresent
In the same file, let’s change the service that comes to be a
LoadBalancer
and set this to the port 80.
service:
type:LoadBalancer
port:80
This will make helm create our external load balancer, and it automatically links it to our application. That's all, the application can be deployed.
helm install ./simple-app
The
helm install
command creates the external load balancer and setup our application in the cluster.
Once it is deployed, it is possible to run
kubectl get services
and see that the load balancer is there.
Updating the application
In case you want to update the application, for example, if you want to change the content of our HTML page. You can use the
helm upgrade
command.
To do it, you need to push a new tag of your container, and run:
helm upgrade ./simple-app
And helm handles everything for you!
Today we saw how to use helm to deploy a kubernetes application, and how to update it. In this example, just a simple HTML page was used, it was intentional just to show how easy a deploy with kubernetes can be.
Comments for Deploying a simple application to kubernetes with Helm