This labs is a very simple example on how to deploy an application on Rancher. We will use tutum/hello-world
During this lab, you will learn how to use Rancher to deploy an image, how to play with Traefik, and how to set up a very simple Jenkins pipeline in order to have continuous delivery.
First of all, you need an account on Github and an API Token. To generate a token, use "Personal access tokens" on your gihub profile and check repo.
stack: A stack is a group of services. Stacks can be used to group together services that together implement an application.
services: Cattle adopts the standard Docker Compose terminology for services and defines a basic service as one or more containers created from the same Docker image.
Rancher: https://rancher.tnt-labs.org Jenkins: http://jenkins-primary.jenkins.traefik.tnt-labs.org
-
Create a new stack called
labs-<user>
-
Add your first service
app
usingtutum/hello-world
. Don't forget to Add TCP health check on port 80. -
Now you can check that your container is running using shell or logs view
-
You container is running but not reachable... So we have to configure a loadbalancer. Rancher provides a HAproxy LB but we will use Traefik with a wildcard dns entry (on Route53). Traefik is already deployed, you just have to add labels on your service using upgrade feature:
traefik.port: 80
traefik.enable: true
traefik.domain: traefik.tnt-labs.org
-
Click on upgrade / finish upgrade in order to clean previous containers
-
Congratulation, your application is available using
<service>.<stack>.traefik.tnt-labs.org
-
You can perform a rolling upgrade using an other image:
dockercloud/hello-world
Now we want to industrialize the deployment part. We will use a Jenkins pipeline in order to upgrade image automatically.
-
Fork the Github project.
-
Go to Jenkins and add your Github token.
-
Now create a new Multibranch Pipeline project called
test-XXX-CI
-
You will see your master branch appear Jenkins will use the Jenkinsfile present on your git repo to generate 1 job per branch. This simple pipeline will have 2 steps: The first part is to configure the rancher-cli, the second part is to deploy your application.
-
Your first pipeline will run automatically. Go on rancher, a new stack is available
<jenkins_job_name>-<branch>
. -
You can browse your website using http://helloworld-application.test-snahelou-ci-master.traefik.tnt-labs.org/
-
Add a Github webhook in order to have continuous deployment.
-
Try to change your docker image into your
docker-compose.yml
and check your pipeline on jenkins -
Congratulation, Rancher performs a rolling update on your service :)
-
Don't forget to delete stack on rancher and your jenkins jobs.
-
Two global environment variables (rancher env api):
- RANCHER_KEY
- RANCHER_URL
-
One global secret RANCHER_SECRET
-
Jenkins plugins:
- Credentials Binding Plugin
- Folder
- CloudBees Credentials Plugin
- Environment Injector Plugin
- Blue ocean