Continuous Deployment on Kubernetes With Spinnaker
In this article, learn how to setup Spinnaker and integrate it with Gitlab CI and Jenkins to build and run CI and CD pipelines.
Join the DZone community and get the full member experience.Join For Free
Spinnaker is an open-source multi-cloud continuous delivery platform that was initially developed by Netflix. It provides support for all major cloud providers as well as Kubernetes. It has been battle-tested by Netflix in production since 2015. It is feature-rich, some of the features that are interesting to us include
- CI Integrations with Jenkins, Gitlab, CircleCI, and more
- Monitoring Integrations
- Deployment strategies
- Manual Judgements
- Chaos Monkey Integration
Our goal is to make reliable deployments using Spinnaker. We will make use of flexible deployment pipelines offered by Spinnaker for deployments at high velocity, fast and often.
Why Spinnaker with Kubernetes
Spinnaker complements Kubernetes by using deployment pipelines allowing for multiple deployment strategies that is not available with Kubernetes deployment API. Deployments are built-in and no custom scripting is needed.
- Ubuntu 16.04 VM on which to install Halyard.
- Spinnaker will be downloaded and run on the single machine Halyard is installed on. At least 16GB RAM and 4 cores are required.
Preparing for Local Debian Installation
Launch a Compute Instance on your cloud of choice using image Ubuntu-16.04 and flavor idc_policy with 16GB RAM, 8 VCPU, and 200GB Disk.
Set the hostname. SSH into the VM using user ubuntu and set the hostname. This is required after a fresh install of Ubuntu, otherwise, sudo command may hang without prompting for the password.
Disable IPv6 completely. Right now many systems and applications still rely on IPv4 and may not work well with IPv6.
To disable IPv6 in APT, run the following command to create a configuration file for APT.
Copy and paste the following line into the file.
Save and close the file. From now on, APT will use IPv4 only.
To disable IPv6 on your Ubuntu Linux system, then you need to make some changes to Linux kernel parameter.
Edit the 99-sysctl.conf file.
Copy and paste the following 3 lines at the bottom of the file.
Save and close the file. Then execute the following command to load the above changes.
Now run the following command. You should see
1, which means IPv6 has been successfully disabled.
Set the proxy for APT. Apt loads all configuration files under /etc/apt/apt.conf.d. We can create a configuration specifically for our proxy there, keeping it separate from all other configurations. Create a new configuration file named proxy.conf.
Open the proxy.conf file in a text editor, and then add the following lines.
Set the proxy for cURL. Create a file .curlrc in your home directory and add following lines.
Set HTTP proxies as Shell environment variables. Create a file /etc/profile.d/proxy.sh and add following lines.
Execute the proxy.sh script file.
Install Java. Install SDKMAN.
Install Java (11.0.3-zulu)
Add java to the PATH variable.
All deployments of Spinnaker require Halyard in order to install, configure, and update Spinnaker. Halyard runs with non-root account.
Create user that will be used to run Halyard and Spinnaker.Shell
Check the version of Halyard installed.Shell
Configure Halyard to run behind proxy. In the file under /opt/halyard/bin/halyard, add the necessary proxy configuration to the variable DEFAULT_JVM_OPTS.Shell
Shutdown and start Halyard.Shell
Setup Minio as Storage Service
Install Docker and configure proxy for Docker daemon.
Install Minio and configure it as storage service that Spinnaker requires for persisting Application settings and configured Pipelines.
Find out the versions of Spinnaker available. Install Google Cloud SDK and read the relevant Google Cloud storage to find out the versions available.
Set Spinnaker version to be deployed, then install Spinnaker.
Restart Spinnaker services.
Kubernetes v2 Provider
Spinnaker’s Kubernetes provider fully supports Kubernetes-native, manifest-based deployments and is the recommended provider for deploying to Kubernetes with Spinnaker.
- Copy your Kubernetes cluster kubeconfig file into /home/ubuntu/.kube/ folder.
- Make sure you are able to run kubectl command successfully from Spinnaker host.
Enable Kubernetes on SpinnakerShell
Apply config and restart services.Shell
Expose Spinnaker to End Users
To prevent inadvertently exposing your cloud infrastructure to the whole world, Halyard installs Spinnaker in its most locked-down form. This means all services only bind to
localhost , which only accepts connections from inside the same server.
We’ll specify the
0.0.0.0 host in both
deck.yml in our
default Halyard deployment with this command
You can test this out by navigating to the instance’s public IP address on port
9000 in your browser.
Spinnaker with Jenkins
Setting up Jenkins as a Continuous Integration (CI) system within Spinnaker lets you trigger pipelines with Jenkins, add a Jenkins stage to your pipeline, or add a Script stage to your CD pipeline.
Make sure that your Jenkins master is enabled:Shell
Add Jenkins masterShell
Re-deploy Spinnaker to apply your changes:Shell
Integrating Spinnaker with GitLab CI Runner
Spinnaker deployment pipelines can be invoked via Webhook. Configure a Webhook trigger for your pipeline as shown below.
Once Webhook is configured, you can trigger this pipeline by calling the endpoint from a Gitlab CI job.
In this article, we set up a Spinnaker instance on Ubuntu and connected it to our Kubernetes environment. We then integrated it with Jenkins so that we can run the script stage on Spinnaker. Finally, we integrated Spinnaker with GitLab CI where we can run our CI pipeline.
Opinions expressed by DZone contributors are their own.