This example shows how to build a simple, multi-tier web application using Kubernetes and Docker.
We will be using Minikube to install our application locally.
Screenshot of App
The example consists of:
- A web frontend
- A redis master (for storage), and a replicated set of redis 'slaves'.
The web frontend interacts with the redis master via javascript redis API calls.
Note: If you are running this example on a Google Container Engine installation, see this Google Container Engine guestbook walkthrough instead. The basic concepts are the same, but the walkthrough is tailored to a Container Engine setup.
You can use the images already pre-defined in the kubernetes manifest files or you can use the below to create your own images and use them:
Replace the realbtotharye with your Dockerhub repository
docker build -t realbtotharye/flask-kubernetes-nginx nginx/
docker push realbtotharye/flask-kubernetes-nginx
docker build -t realbtotharye/flask-kubernetes-redis flask-redis/
docker push realbtotharye/flask-kubernetes-redis
Make sure to install Minikube and then proceed with ensuring kubectl works and your cluster is up.
This example requires a running Kubernetes cluster. First, check that kubectl is properly configured by getting the cluster state:
$ kubectl cluster-info
If you see a url response, you are ready to go.
This section shows the simplest way to get the example work. If you want to know the details, you should skip this and read the rest of the example.
Start the guestbook with one command:
Ensure you are in the working dir
cd kubernetes-flask-example
$ kubectl create -f .
service "redis-master" created
deployment "redis-master" created
service "redis-slave" created
deployment "redis-slave" created
service "frontend" created
deployment "frontend" created
Then, list all your Services:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend NodePort 10.99.150.67 <none> 80:32515/TCP 34s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 48m
redis-master ClusterIP 10.104.124.32 <none> 6379/TCP 34s
redis-slave ClusterIP 10.104.43.119 <none> 6379/TCP 34s
Now with using minikube we can run the following to get the url for the service and access our app:
minikube service frontend --url
Use the URL given to us here and we can access it. If you are not using minikube then you can access this via the ClusterIP or setup a load balancer or proxy to access the application.
Clean up the guestbook:
$ kubectl delete -f .