Sunday 30 October 2022

Google Kubernetes Engine - gcloud and kubectl examples (Part 1)

 








In this post, we have given the most useful commands of google kubernetes emgine. This will be handy reference.  

Create Cluster 

gcloud container clusters create my-cluster --zone us-central1-c --project my-kubernetes-project-123456 


Get Credentials. This step helps to initialize the environment of cloud shell 

gcloud container clusters get-credentials my-cluster --zone us-central1-c --project my-kubernetes-project-123456 


Create deployment in kubernetes  

kubectl create deployment hello-world-rest-api --image=shareGCP/hello-world-rest-api:0.0.1.RELEASE 

kubectl get deployment 


Expose the deployment to internet. This create a service in kubernetes 

kubectl expose deployment hello-world-rest-api --type=LoadBalancer --port=8080 

kubectl get services 

kubectl get services --watch

 


Check whether the service is up  

curl 55.184.204.214:8080/hello-world 


Manually Scale in/out the number of instances/pods  

kubectl scale deployment hello-world-rest-api --replicas=3 


Manually Scale in/out the number of nodes 

gcloud container clusters resize my-cluster --node-pool default-pool --num-nodes=2 --zone=us-central1-c
 


Setup autoscaling for the deployment and this increases or decreases number of pods 

kubectl autoscale deployment hello-world-rest-api --max=4 --cpu-percent=70 

kubectl get hpa 


Setup autoscale for number of nodes in the cluster  

gcloud container clusters update my-cluster --enable-autoscaling --min-nodes=1 --max-nodes=10
 


Create config map in kubernets so that these values can be used by the microservice deployed  

kubectl create configmap hello-world--testconfig --from-literal=TEST_DB_NAME=oracle 

kubectl get configmap 

kubectl describe configmap hello-world-testconfig 


Store the credentials in kubernetes. This will be accessible for microservices 

kubectl create secret generic hello-world-secrets-2 --from-literal=RDS_PASSWORD=dummy 

kubectl get secret 

kubectl describe secret hello-world-secrets-2 


Kubernetes deployment changes via yaml file  

kubectl apply -f deployment.yaml 


Create additional node pool -- Don't try its costly 

gcloud container node-pools create new_pool_name --zone=us-central1-c --cluster=my-cluster 


List the node pools creates as part of your cluster  

gcloud container node-pools list --zone=us-central1-c --cluster=my-cluster 


Set cluster name in your default configuration. This allows to execute kubectl commands without cluster name 

gcloud config set container/cluster my-cluster



Sunday 30 October 2022 by Team search · 0

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.