What are we doing?
We are deploying the Docker example voting app as a Helm Release using Codefresh.
(3) - result, vote and worker micro-services
We will show you how to:
- Add a repository to Codefresh.
- Create a matrix pipeline to build (3) micro-services in parallel.
- Deploy the Docker example voting app to your Kubernetes cluster using Codefresh + Helm.
- The Helm chart uses a combination of local-charts for (3) and community charts for Redis and Postgres.
Now onto the How-to!
PreReqs:
Some popular Kubernetes options
- Amazon KOPs Tutorial
- Amazon EKS (Preview)
- Azure Container Service (Moving to AKS)
- Azure Kubernetes Service (Preview) Webinar
- Google Kubernetes Engine Tutorial
- IBM Cloud Container Service
- Stackpoint Cloud
Fork this Github Repository
Either Fork or copy this repositories content to your Github Account or a GIT repository in another Version Control System.
You'll need to configure your Kubernetes cluster in Codefresh. See link above.
If you'd like to add your own Docker Registry
Add Docker Registry to Codefresh
If you want to us Codefresh Integrated Docker Registry
Example commands below use cfcr (Codefresh Integrated Registry). Update if you decide to use your own Docker Registry
Configure Kubernetes namespace with Pull Secret
Command to create Pull Secret
kubectl create secret docker-registry -n <kubenetes_namespace> cfcr --docker-server=r.cfcr.io --docker-username=<codefresh_username> --docker-password=<cfcr_token> --docker-email=<codefresh_email>
Command to patch Service Account with Pull Secret
kubectl patch <service_account_name> <kubernetes_namespace> -p "{\"imagePullSecrets\": [{\"name\": \"cfcr\"}]}" -n <kubernetes_namespace>
Create Codefresh CLI Key
- Create API key in Codefresh
- Click GENERATE button.
- Copy key to safe location for later use in
CODEFRESH_CLI_KEY
variable.
If you decided not use cfcr
as your Docker Registry then you can skip this step.
Edit the Codefresh YAML in ./result
, ./vote
and ./worker
directories with your friendly Docker registry name for registry in YAML.
In Codefresh add a new Repository and select example-voting-app
- Click Add New Repository button from Repositories screen.
- Select the example-voting-app repository you forked or clone to your VCS/Organization. (master branch if fine) Then click NEXT button.
- Click SELECT for CODEFRESH.YML option.
- Update PATH TO CODEFRESH.YML with
./codefresh-matrix-pipeline.yml
. Then click NEXT button. - Review Codefresh YAML. Then click CREATE button.
- Click CREATE_PIPELINE button.
You'll arrive at the example-voting-app
pipeline.
Now we need to configure some Environment Variables for the Repository.
- Click on General tab in the
example-voting-app
Repository page. - Add the following variables below. (Encrypt the sensitive variables). Click ADD VARIABLE link after every variable to add.
CODEFRESH_ACCOUNT
Your Codefresh Account Name (shown in lower left of Codefresh UI). If you chose to use CFCRCODEFRESH_CLI_KEY
Your Codefresh CLI Key ENCRYPT.KUBE_CONTEXT
Your friendly Kubernetes Cluster Name to use for release.KUBE_NAMESPACE
Kubernetes namespace to use for release.KUBE_PULL_SECRET
Kubernetes Pull Secret name.
The matrix pipeline is already configured and named after your GIT repository example-voting-app
.
We need to setup the following (3) pipelines.
From Pipelines page of example-voting-app
repository.
- Click ADD PIPELINE (do this 3 times)
- Name
example-voting-app1
toexample-voting-app-result
; Set WORKFLOW to YAML, Set Use YAML from Repository; Edit PATH_TO_YAML./result/codefresh-result-pipeline.yml
; Click SAVE button at bottom of page. - Name
example-voting-app2
toexample-voting-app-vote
; Set WORKFLOW to YAML, Set Use YAML from Repository; Edit PATH_TO_YAML./vote/codefresh-vote-pipeline.yml
; Click SAVE button at bottom of page. - Name
example-voting-app3
toexample-voting-app-worker
; Set WORKFLOW to YAML, Set Use YAML from Repository; Edit PATH_TO_YAML./worker/codefresh-worker-pipeline.yml
; Click SAVE button at bottom of page.
Now we need to get your Codefresh Pipeline IDs to setup parallel builds.
Two options:
- CLI
codefresh get pipelines
- UI
- Open Repository.
- Click on each pipeline.
- Expand General Settings.
- Tempoary toggle on Webhook.
- Capture ID from the curl command shown.
Record your Pipeline IDs
- Open your
example-voting-app
Codefresh pipeline. - Add the following environment variable.
PARALLEL_PIPELINES_IDS
with space delimited Codefresh Pipeline IDs. - Click ADD VARIABLE link below variable listing.
- Click SAVE button at bottom of page.
Now you can run your example-voting-app pipeline to produce a Helm Release.
When the build is finished you will see a new Helm Release for example-voting-app
Hopefully this has given you a somewhat overall picture of setting up Codefresh to run a Kubernetes deployment utilizing Helm.
Now you can play with the release or do something similar with your own application.
We'll be adding a Blog Post and additional followups to this example. Ex. Unit Tests, Integration Tests, Security Tests and Functional Testing.
If you'd like to schedule a demo of Codefresh to get help adding your own CI/CD steps to your Codefresh Pipelines Click Here
ORIGINAL CONTENT BELOW, PLEASE NOTE DOCKER SWARM DOES NOT WORK AT THIS TIME.
Download Docker. If you are on Mac or Windows, Docker Compose will be automatically installed. On Linux, make sure you have the latest version of Compose. If you're using Docker for Windows on Windows 10 pro or later, you must also switch to Linux containers.
Run in this directory:
docker-compose up
The app will be running at http://localhost:5000, and the results will be at http://localhost:5001.
Alternately, if you want to run it on a Docker Swarm, first make sure you have a swarm. If you don't, run:
docker swarm init
Once you have your swarm, in this directory run:
docker stack deploy --compose-file docker-stack.yml vote
- A Python webapp which lets you vote between two options
- A Redis queue which collects new votes
- A .NET worker which consumes votes and stores them inβ¦
- A Postgres database backed by a Docker volume
- A Node.js webapp which shows the results of the voting in real time
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.