In our previous section we learnt how to operate google cloud platform using a quick start boiler plate for python, in this section we will learn about the containers.
Containers are the heart of google cloud platform, our applications are deployed on containers(Dockers or google containers), these containers are a miniature version of virtual machines.Containers is a bundle of all the required components which are required to run a specific application.There is a one to many relations ship between a virtual machine and containers.
To operate and orchestrate multiple containers google provides; Kubernetes.
Kubernetes is used for automating deployment, scaling, and management of containerized applications.
Lets understand a few terms:
Single POD under Kubernetes
To simplify , lets host a word press( The popular CMS ) website on google cloud.Lets create a hello world cluster which will host our pods.
$ gcloud container clusters create hello-world --num-nodes 1 --machine-type g1-small
Lets build our POD with single container and fetch the docker image from registry.
kubectl run wordpress --image=tutum/wordpress --port=80
Lets expose the POD by a service which allows external traffic.
kubectl expose deployment wordpress --type=LoadBalancer
This expose command creates:
Lets try to see our word press service.
Lets try to open our word press installation which is running in a Dockers container of
our POD and hosted on a single node inside the Kubernetes cluster.
Multiple PODS under Kubernetes
Lets take another case, where we have a cluster of containers and we will push a custom docker image to our pods via kubermetes.
Tip:You can also build your Dockers images from the gcloud command line and push it to the Google's container registry.
Lets say you have pulled a Dockers image from Dockerhub.com and you have done some modifications to it.
Now you can save a snapshot of the running Dockers image and save it to google container’s registry.
docker pull --- url
docker commit (snapshot) or you can do a docker build also if you have a docker file.
Now push it to gcr.io ($DEVSHELL_PROJECT_ID is the current project id)
gcloud docker -- push gcr.io/$DEVSHELL_PROJECT_ID/clustername
Now lets use kubernetes to manage our containers in the cluster.
$gcloud container clusters get-credentials clustername( to get credentials for cluster)
Now lets create the pods with the YAML file we have( The resource file)
$kubectl create -f resources.yaml
If all is fine, your resources will be created and pods will start
$ kubectl get pods ( keep refreshing till status changes for pods)
Now check the status of the service by.
$kubectl get services servicename ( service name is defined in your yaml file.)
Troubleshooting Section:
If status of pods is (ImagePullBackOff or ErrImagePull), reason could be either your Docker
image is not pushed to GCR properly or your YAML file has wrong docker image name.
Do a grep on the YAML file for your image name and see if its there.
In this section, we learnt how Google containers work and how we can use Kubernetes to control the PODS and how we can deploy custom images inside the POD containers.
Keep Reading !
No comments:
Post a Comment