A simple cloud native app for Cloud Native Victoria Meetup
This tutorial demostrates deploying a cloud native application that runs on Kubernetes along side Prometheus, Fluentd and Istio to provide a complete platform to run your microservices on.
Configure google cloud region and zone
gcloud config set compute/region us-west1
gcloud config set compute/zone us-west1-b
Create Kubernetes Cluster
gcloud container clusters create cloud-native-app \
--machine-type n1-standard-1 \
--num-nodes 3 \
--cluster-version 1.7.5
Wait for the kubernetes cluster to come up
it might take couple of minutes
gcloud container clusters list
NAME ZONE MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
cloud-native-app us-west1-b 1.7.5 35.197.117.21 n1-standard-1 1.7.5 3 RUNNING
Configure kubectl to point to the kubernetes cluster
gcloud container clusters get-credentials cloud-native-app --zone us-west1-b --project {PROJECT_NAME}
Follow the guide on Istio's website to install Istio on Kubernetes. Just make sure you get to the Verify the installation step.
Now you have istio and the addons like Prometheus, Grafana and ServiceGraph installed!
go run main.go
2017/09/20 15:43:29 starting web server on port :8080
In a new terminal test the application
curl localhost:8080
You've hit the home page of the cloud native app with hostname "hostname.local" on node "".
Cool! Our app works!
Lets build a docker container
GOOS=linux GOARCH=amd64 go build -v .
docker build -t anubhavmishra/cloud-native-app:v0.1.0 .
docker tag anubhavmishra/cloud-native-app:v0.1.0 anubhavmishra/cloud-native-app:latest
Now lets test the docker image
docker run -it -p 8080:8080 anubhavmishra/cloud-native-app
In a new terminal curl the application
curl localhost:8080
You've hit the home page of the cloud native app with hostname "docker-hostname" on node "".
Push the docker image to docker registry (docker hub)
docker push anubhavmishra/cloud-native-app:v0.1.0
docker push anubhavmishra/cloud-native-app:latest
Awesome! Now we have a docker image of our app. Lets deploy it to kubernetes
kubectl apply -f kubernetes/cloud-native-app-deployment.yaml
Check if it is running
kubectl get pods | grep cloud-native-app
cloud-native-app-913471705-4j2zx 1/1 Running 0 15s
Test the app
kubectl port-forward cloud-native-app-913471705-4j2zx 8080:8080
In a new terminal curl the application
curl localhost:8080
You've hit the home page of the cloud native app with hostname "cloud-native-app-913471705-4j2zx" on node "node-name".
Lets expose this application to the world
kubectl apply -f kubernetes/cloud-native-app-service.yaml
Check if the service is up
kubectl get service cloud-native-app
Give it a minute for the
EXTERNAL-IP
to show up
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cloud-native-app 10.7.253.76 35.203.186.75 80:31567/TCP 2m
In a new terminal curl the EXTERNAL-IP
curl 35.203.186.75:8080
You've hit the home page of the cloud native app with hostname "cloud-native-app-913471705-4j2zx" on node "node-name".
Scale the application
kubectl scale deployment cloud-native-app --replicas=3
Check if the application is scaled
kubectl get pods | grep cloud-native-app
cloud-native-app-913471705-4j2zx 1/1 Running 0 16m
cloud-native-app-913471705-djpnz 1/1 Running 0 58s
cloud-native-app-913471705-v247t 1/1 Running 0 58s
Get some logs
kubectl logs -f {POD_NAME}
- Look at fluentd and GCP
First we delete currently running cloud-native-app
service since it exposed as LoadBalancer
type
kubectl delete -f cloud-native-app-service.yaml
Let's explore the our microservices
vim kubernetes/cloud-native-microservices-v1.yaml
kubectl apply -f <(istioctl kube-inject -f kubernetes/cloud-native-microservices-v1.yaml --namespace=istio-system)
kubectl apply -f <(istioctl kube-inject -f kubernetes/cloud-native-app-ingress.yaml --namespace=istio-system)
Now lets find our ingress
kubectl get ingress cloud-native-app-gateway
kubectl describe ingress cloud-native-app-gateway
curl the ip or domain
curl -H 'Host: cloud-native-app.livedemos.xyz' 104.196.249.219
curl cloud-native-app.livedemos.xyz
Lets loop it!
while true; do curl -H 'Host: cloud-native-app.livedemos.xyz' 104.196.249.219; echo ""; sleep 0.5;done
Deploy v2 of the applications
kubectl apply -f <(istioctl kube-inject -f kubernetes/cloud-native-microservices-v2.yaml --namespace=istio-system)
istioctl create -f rules/foo.yaml --namespace=istio-system
istioctl create -f rules/bar.yaml --namespace=istio-system
istioctl get route-rules --namespace=istio-system
foo-istio-system
bar-istio-system
Lets now try to shape some traffic for foo
application
vim rules/foo.yaml
istioctl replace -f rules/foo.yaml --namespace=istio-system
I want to canary a mobile device
istioctl create -f rules/foo-mobile.yaml --namespace=istio-system
istioctl delete route-rule foo-canary --namespace istio-system
Deny
istioctl mixer rule create global foo.istio-system.svc.cluster.local -f rules/foo-deny.yaml --namespace istio-system
istioctl mixer rule delete global foo.istio-system.svc.cluster.local --namespace istio-system