Creating & Deploying own image to Google Kubernetes Engine(GKE) using Terraform(Part 1)

Overview

  • How to create a simple Docker container image using Dockerfile
  • General use of Docker Container registry DockerHub
  • Deployment of own docker image to Kubernetes using YAML file
  • Google Kubernetes Engine Cluster Creation using Terraform Script
  • How to create terraform cluster deployment file with the help of Kubernetes configuration file(YAML).
  • Some optional deployment using terraform like Google Virtual Private Cloud(VPC) Network & more.

Step 1. Creating a simple docker container image

mkdir blog-workspacecd blog-workspace
nano main.py
nano requirements.txt
nano Dockerfile
docker build -t <your_image_name>:<image_tag(Optional)> .
docker images
docker run -it -p 2000:80 --name <name_you_want> <your_image_name>:<image_tag(Optional)>

Step 2. General use of docker container registry Dockerhub

docker login
docker tag <your-image-name> <hub-username>/<repo-name/you-can-give-any-name>:<version-tag>
docker push <hub-username>/<repo-name/you-can-give-any-name>:<version-tag>

Step 3: Deployment of own docker image to Kubernetes using YAML file

gcloud config set compute/region <your google cloud region>gcloud config set compute/region <your google cloud zone>
gcloud container clusters create <your cluster's name> --num-nodes=<put no of nodes you want>
gcloud container clusters get-credentials <your cluster's name> --zone=<your cluster's zone>
nano config.yaml
kubectl apply -f config.yaml
kubectl get all
glcoud container clusters delete <your cluster's name> --zone=<your cluster's zone>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store