GKE is a managed Kubernetes platform designed to simplify the deployment, management, and scaling of containerised applications. It is build on top of Kubernetes, and open-source container orchestration tool developed by Google. GKE enables users to create, manage, and scale Kubernetes clusters, which are groups of virtual machines (VMs) running containerised applications.
Kubernetes – A Microservice Journey – Getting Started
Step 1: Create a Kubernetes cluster with the default node pool
gcloud container clusters create or use cloud console
Step 2: Login to Cloud Shell
Step 3: Connect to Kubernetes Cluster
gcloud container clusters get-credentials my-cluster --zone us-central1-a --project solid-cource-258105
Step 4: Deploy Microservice to Kubernetes
- Create deployment & service using kubectl commands
kubectl create deployment hello-world-rest-api --image="image_url"kubectl expose deployment hello-world-rest-api --type=LoadBalancer --port=8080
Step 5: Increase number of instances of your microservice:
kubectl scale deployment hello-world-rest-api --replicas=2
Step 6: Increase number of nodes in your Kubernetes cluster:
gcloud container clusters resize my-cluster --node-pool my-node-pool --num-nodes 5- You are NOT happy about manually increasing number of instances and nodes you can do autoscaling
Step 7: Setup auto scaling for your microservice
kubectl autoscale deployment hello-world-rest-api --max=10 --cpu-percentage=70
Step 8: Setup auto scaling for your Kubernetes Cluster
gcloud container cluster update cluster-name --enable-autoscaling --min-nodes=1 --max-nodes=10
Step 9: Add some application cofiguration for your microservice
- Config Map – Kuberctl create configmap todo-web-application-config –form-literal=RDS_DB_NAME=todos
Step 10: Add password configuration for your microservice
- Kubernetes Secrets – kubctl create secret generic todo-web-application-secrets-1 –form-literal=RDS_PASSWORD=dummytodos
Kubernetes Deployment YAML – Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: hello-world-rest-api
name: hello-world-rest-api
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: hello-world-rest-api
template:
metadata:
labels:
app: hello-world-rest-api
spec:
containers:
- image: in28min/hello-world-rest-api:0.0.3.RELEASE
name: hello-world-rest-api
Kubernetes Deployment YAML – Service
apiVersion: v1
kind: Service
metadata:
labels:
app: hello-world-rest-api
name: hello-world-rest-api
namespace: default
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
app: hello-world-rest-api
sessionAffinity: None
type: LoadBalancer
Kubenetes – A Microservice Journey – The End!
Step 11: Deploy a new microservice which needs nodes with a GPU attached
- Attach a new node pool with GPU instances to your cluster
gcloud container node-pools-create POOL_NAME CLUSTER_NAMEgcloud container node-pools list --cluster CLUSTER_NAME
- Deploy the new mircoservice to the new pool by setting up nodeSelector in the deployment.yaml
nodeSelector: cloud.google.com/gke-nodepool: POOL_NAME
Step 12: Delete the Microservices
- Delete service – kubectl delete service
- Delete deployment – kubeclt delete deployment
Step 13: Delete the Cluster
- gcloud container clusters delete