Docker Build, Continuous Integration, and Deployment to Kubernetes using Kubectl CLI for a Node JS application
A simple Node JS application with unit tests and coverage reports using mocha and istanbul.
This repo demonstrates the following features:
- Set up serverless CI, i.e. on Shippable-provided infrastructure
- Set up CD pipelines for a Kubernetes cluster running on Amazon EC2
- Perform CI tests
- Perform docker build and push image to Docker Hub
- Automatically deploy image to TEST environment
- Manually deploy image to PROD environment
- Set up runSh job type in Shippable using
kubectl
CLI (for declarative deploy job, see this sample project)
- Fork this repo into your source code account (e.g. GitHub)
- Create an account (or login) on Shippable with your SCM account
- Create an integration on Shippable for your Docker Hub account
- Update the CI configuration in
shippable.yml
file with your integration names (see comments in file) - Follow these setup instructions to enable your forked repo for CI and run a build
- Create an integration for Kubernetes
- All pipeline config is in
shippable.resources.yml
andshippable.jobs.yml
. Check these files and update config wherever the comment asks you to replace with your specific values - Follow instructions to add your Continuous Deployment pipeline
- Right-click on the runSh job in the SPOG view named 'deploy_kubernetes_runcli_test' and run the job
- This demo uses custom scripting jobs called 'runSh' jobs in Shippable - learn how moe about runSh jobs
- Your app should be deployed to your Kubernetes cluster as a Test pod
- Follow instructions to connect your Continuous Integration project to your Continuous Delivery pipelines(for this demo, just uncomment the
trigger
integration in shippable.yml) - Right-click on the runSh job in the SPOG view named 'deploy_kubernetes_runcli_prod' and run the job to deploy to a Prod pod
- Make a change to your forked repo and commit to GitHub - watch your pipeline automatically execute CI with push to Docker Hub and automatic deployment to the Test environment in Kubernetes
- Then right-click to deploy the newest changes to the Prod environment
Your end-to-end pipeline is complete! Now, any change you make to the application will be deployed to your Kubernetes Test pod and be ready to manually deploy a Prod pod, as well.
Instructions for launching a Kubernetes cluster using KOPS:
https://kubernetes.io/docs/getting-started-guides/kops/
Determine settings for your cluster:
YOUR_CLUSTER_DOMAIN_NAME="your.cluster-name.com"
YOUR_ZONE="your_aws_zone" # e.g. us-east-1c
Build the cluster configuration (replace the zone and cluster name with your values):
kops create cluster --zones=$YOUR_ZONE $YOUR_CLUSTER_DOMAIN_NAME
Create the cluster in AWS:
kops update cluster $YOUR_CLUSTER_DOMAIN_NAME
To add a Kube UI:
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.4.0.yaml
kubectl proxy
Then navigate to http://127.0.0.1:8001/ui
Delete the cluster:
kops delete cluster $YOUR_CLUSTER_DOMAIN_NAME --yes
To add ability to pull images from private registry:
https://kubernetes.io/docs/user-guide/images/#specifying-imagepullsecrets-on-a-pod