In this article we will show you how to set up the deployment of an example application (a cool voting app in our case) using werf. It is better to start with a short introduction first if you haven’t read it yet.
Prepare your host
- Install dependencies (Docker and Git).
- Install multiwerf and werf.
Make sure you have werf
command available in your shell before proceeding to the next step:
werf version
Prepare your Kubernetes and Docker Registry
You should have access to the Kubernetes cluster and be able to push images to your Docker Registry. Docker Registry should also be accessible from the Kubernetes cluster to pull images.
If your Kubernetes and Docker Registry are running already:
- Perform the standard docker login procedure into your Docker Registry from your host.
- Make sure your Kubernetes cluster is accessible from your host (if the
kubectl
tool is already set up and running, thenwerf
will also work just fine).
Or use one of the following instructions to set up the local Kubernetes cluster and Docker Registry in your OS:
- Install minikube.
-
Start minikube:
minikube start --driver=docker
IMPORTANT: If you have already started minikube make sure it uses
docker
driver, restart minikube otherwise (by usingminikube delete
and start command shown above). -
Enable the minikube registry addon:
minikube addons enable registry
Output should contain a line like:
... * Registry addon on with docker uses 32769 please use that instead of default 5000 ...
Remember the port
32769
. -
Run the following port forwarder in the separate terminal replacing
32769
port with the port from the previous step:docker run -ti --rm --network=host alpine ash -c "apk add socat && socat TCP-LISTEN:5000,reuseaddr,fork TCP:host.docker.internal:32769"
-
Run a service with a binding to 5000 port:
kubectl -n kube-system expose rc/registry --type=ClusterIP --port=5000 --target-port=5000 --name=werf-registry --selector=actual-registry=true
-
Run the following port forwarder in the separate terminal:
kubectl port-forward --namespace kube-system service/werf-registry 5000
- Install minikube.
-
Start minikube:
minikube start --driver=docker
IMPORTANT: If you have already started minikube make sure it uses
docker
driver, restart minikube otherwise (by usingminikube delete
and then start command shown above). -
Enable the minikube registry addon:
minikube addons enable registry
Output should contain a line like:
... * Registry addon on with docker uses 32769 please use that instead of default 5000 ...
Remember the port
32769
. -
Run the following port forwarder in the separate terminal replacing
32769
port with the port from the step 3:docker run -ti --rm --network=host alpine ash -c "apk add socat && socat TCP-LISTEN:5000,reuseaddr,fork TCP:host.docker.internal:32769"
-
Run the following port forwarder in the separate terminal replacing
32769
port with the port from the step 3:brew install socat socat TCP-LISTEN:5000,reuseaddr,fork TCP:host.docker.internal:32769
- Install minikube.
-
Start minikube:
minikube start --driver=docker
IMPORTANT: If you have already started minikube make sure it uses
docker
driver, restart minikube otherwise (by usingminikube delete
and then start command shown above). -
Enable the minikube registry addon:
minikube addons enable registry
-
Run the following port forwarder in the separate terminal:
sudo apt-get install -y socat socat -d -d TCP-LISTEN:5000,reuseaddr,fork TCP:$(minikube ip):5000
Deploy an example application
-
Clone the example application’s repository:
git clone https://github.com/werf/quickstart-application cd quickstart-application
-
Run the converge command using your Docker Registry for storing images (
localhost:5000/quickstart-application
repository in the case of a local Docker Registry).werf converge --repo localhost:5000/quickstart-application
NOTE: werf
uses the same settings to connect to the Kubernetes cluster as the kubectl
tool does: the ~/.kube/config
file and the KUBECONFIG
environment variable. werf also supports --kube-config
and --kube-config-base64
parameters for specifying custom kubeconfig files.
Check the result
When the converge command is successfully completed, it is safe to assume that our application is up and running. Let’s check it!
Our application is a basic voting system. Go to the following URL to vote:
minikube service --namespace quickstart-application --url vote
Go to the following URL to check the result of voting:
minikube service --namespace quickstart-application --url result
How it works
To deploy an application using werf, we should define the desired state in the Git (as set out in the introduction).
-
We have the following Dockerfiles in our repository:
vote/Dockerfile result/Dockerfile worker/Dockerfile
-
The
werf.yaml
file references those Dockerfiles:configVersion: 1 project: quickstart-application --- image: vote dockerfile: vote/Dockerfile context: vote --- image: result dockerfile: result/Dockerfile context: result --- image: worker dockerfile: worker/Dockerfile context: worker
-
Kubernetes templates for
vote
,db
,redis
,result
andworker
components of the application are described in the files of a.helm/templates/
directory. Components interact with each other as shown in the diagram:
- A front-end web app in Python or ASP.NET Core lets you vote for one of the two options;
- A Redis or NATS queue collects new votes;
- A .NET Core, Java or .NET Core 2.1 worker consumes votes and stores them in…
- A Postgres or TiDB database backed by a Docker volume;
- A Node.js or ASP.NET Core SignalR web-app shows the results of the voting in real-time.
What’s next?
Check the “Using werf with CI/CD systems” article or refer to the guides.