CI/CD for Kubernetes With Jenkins and Spinnaker (Part 2)
Create and deploy and application in that will be automatically updated with this tutorial with Spinnaker.
Join the DZone community and get the full member experience.Join For Free
In our last post, we installed Spinnaker using Halyard. Now we will create applications and pipelines that will be continuously deployed in our Kubernetes Cluster.
Before creating an application we will add
docker registry to cache images which will be used to deploy clusters in application deployments.
hal config provider docker-registry add my-registry --address registry.com --repositories nginx busybox --username admin --password
Note: In the above command, we have listed Nginx, Busybox repositories as an example. Also, we assume you have a private docker-registry setup that you will be using here. By default, it uses Docker Hub to pull Docker images.
After adding registry and repository we need to deploy changes to Spinnaker. The command below will update the Spinnaker configuration.
hal deploy apply
Now let's get started with creating an application.
You should create a load balancer here from the load balancer tab. Choose NodePort in the configuration of load balancer if you want to access the application publicly.
Once the application is created you will be redirected to an application screen where, on top, you will see Pipeline. Click on that and click create the pipeline.
Now on the pipeline configuration, we will create an automated trigger, indicated in the screenshot below.
You should select the Docker registry here. We are using Docker registry for this case but you can select different options as well. Whatever option you choose, you need to add that to the Spinnaker configuration using Halyard in the same way we added Docker registry in the first step.
Next, add a new stage which will deploy an image from the repository we added, and create a server group.
Select the Kunernetes account where you will deploy the application. Select the image from "Containers," "Load Balancer" (which we created earlier) and fill in other details specific to your application. Click on Add to save the cluster.
Spinnaker supports multiple deployment strategies while updating the Docker image.
Highlander: Destroy all previous server group in the cluster once the new server group passes the health check.
Red/Black: Disable all previous server group in the cluster once the new server group passes the health check.
None: Create the next server group with no impact to the previous server group.
Custom: We can create our custom strategy.
Come back to the pipeline configuration window and click on Save Changes (right bottom) to save the pipeline configuration. And there we go; we have our pipeline setup ready.
Once the new image is pushed to the Docker registry we set up, this pipeline will be triggered and the application will be updated.
Next article will show you how we can run Cron jobs on the Kubernetes cluster using Spinnaker.
Stay tuned until next one.
Opinions expressed by DZone contributors are their own.