Cloud Container, Pods, Kubernetes – Command Summary

keikis org Apr 18, 2018 @ 4:16 pm

Kubernetes –  Docker – GCloud in a Nutshell


Options available for cloud container cluster

keikis@keikis-academy:~$ gcloud container clusters


Creating cluster

Normal nodes CPUs

gcloud container clusters create test –scopes “cloud-platform” –num-nodes 2 –zone us-central1-a

One small nodes CPUs 

gcloud container clusters create test –scopes “cloud-platform” –machine-type g1-small –num-nodes 1 –zone us-central1-a

List Zones & Status

jgarcicr@keikis-academy-186711:~$ gcloud compute zones list


Get info of the cluster

jgarcicr@keikis-academy-186711:~$ gcloud container clusters list



Build the application’s Docker image

jgarcicr@keikis-academy-186711:~/kubernetes/test$ docker build -t .


Push the image to Google Container Registry so that your cluster can access the image

jgarcicr@keikis-academy-186711:~/kubernetes/test$ gcloud docker — push



Run the container locally

docker run –rm -p 8080:8080${PROJECT_ID}/hello-app:v1

Use kubectl to deploy the resources to the cluster

kubectl create -f academy.yaml


Create the academy service

kubectl create -f academy-service.yaml



Show Docker Images

docker image ls -a


Get Cluster Info

jgarcicr@keikis-academy-186711:~/kubernetes/test$ kubectl cluster-info


Switch Between Cluster

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ gcloud container clusters list

Show Config To Switch Between Contexts

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl config view


Change Cluster Context to test Cluster & Show Nodes

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl config set current-context gke_keikis-academy-186711_us-central1-a_test

(also by cluster-name) gcloud config set container/cluster cluster-academy


jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl get nodes                                                            


Switch Cluster Context to academy Cluster & Show Nodes

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl config set current-context gke_keikis-academy-186711_us-central1-a_cluster-academy


jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl get nodes


Show Current Context

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ kubectl config current-context  


Update Credentials for this Context

to resolve The connection to the server localhost:8080 was refused – did you specify the right host or port?

jgarcicr@keikis-academy-186711:~/kubernetes/keikis-academy-docker$ gcloud container clusters get-credentials cluster-academy –zone us-central1-a


Track the status of the deployment

kubectl get deployments

Once the deployment is complete you can see the pods that the deployment created

kubectl get pods

Query for pods

kubectl get  pods


More info for pods

kubectl describe  pods


Get more info about service. The service’s external IP address to use

kubectl describe service academy

Service Info. Look out for the external IP still pending

jgarcicr@keikis-academy-186711:~/kubernetes/test$ kubectl get services


Get all info with containers name in json format

jgarcicr@keikis-academy-186711:~/kubernetes/test/test$ kubectl get pods -o json



Remove single image

docker rmi image_name:version/image-id

Remove all images

docker rmi $(docker images -qf “dangling=true”)

Kill containers and remove them

docker rm $(docker kill $(docker ps -aq))

Delete deployment

Once the deployment has the same number of available pods as desired pods, the deployment is complete. If you run into issues with the deployment, you can delete it and start over:

kubectl delete deployments academy-frontend

Delete Cluster in Zone. Zone is mandatory

jgarcicr@keikis-academy-186711:~$ gcloud container clusters delete test –zone  us-central1-a


Delete pods

kubectl delete pods <pod>

Delete pods force

kubectl delete pods <pod> –grace-period=0 –force

Delete all nodes

kubectl delete node –all


View the Container’s logs by pod name with only one container

kubectl logs dapi-envars-resourcefieldref

Logs of Pod in Container

kubectl logs test-frontend-3341430478-2rq35 test-app


One comment

  1. Great article with excellent summary,
    Thanks a lot!

Leave a Reply

Social media & sharing icons powered by UltimatelySocial