ALC 4 Cloud Challenge Phase II using GCP Virtual Machine


  1. Cloud SDK installed and setup on your local machine
  2. Windows Professional version
  3. Administrative rights on your local machine
  4. Google Cloud Account
  5. Internet
  1. Create the virtual machine,
  2. Install node and docker,
  3. Create your application and docker image,
  4. Push the created image to google container registry ,
  5. Create Kubernetes cluster,
  6. Deploy the gcr container to the cluster, and
  7. Expose the deployment using a LoadBalancer.
gcloud beta compute --project=spikey-bigtable-new instances create challenge-vm --zone=us-central1-a --machine-type=g1-small --tags=http-server,https-server --image=ubuntu-1604-xenial-v20191010 --image-project=ubuntu-os-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=ubuntu-vm
  • “ — machine-type” of “g1-small” to reduce cost
  • “ — image” of “ubuntu-1604-xenial” for the simple reason that I am a lover of Ubuntu
  1. Stop the instance
  2. Click the Edit button at the top of the page.
  3. Under Custom metadata, click Add item.
  4. Add your startup script using one of the following keys:
  • startup-script: Supply the startup script contents directly with this key.
  • startup-script-url: Supply a Cloud Storage URL to the start script file with this key.
#! /bin/bashsudo apt-get updatesudo apt-get install apt-transport-https ca-certificates curl gnupg-agent  software-properties-commoncurl -fsSL | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt-get updatesudo apt-get install docker-ce docker-ce-cli -ycurl -sL | sudo -E bash -sudo apt-get install nodejs
sudo google_metadata_script_runner --script-type startup --debug
gcloud compute ssh name_of_instance
mkdir challenge-home
cd challenge-home
  1. Install yarn,
sudo npm install -g yarn
yarn add global create-react-app
# windows users
yarn create-react-app challenge-app
cd challenge-app
yarn start
# for Ubuntu users
create-react-app challenge-app
cd challenge-app
yarn start
gcloud compute firewall-rules create node-test-rule --action=ALLOW --direction=INGRESS --rules=tcp:3000 --source-ranges=""
ctrl + c
touch Dockerfile
FROM node as build-deps
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build
FROM nginx:1.12-alpine
COPY --from=build-deps /usr/src/app/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
sudo docker build . -t udoyen/challenge-image
sudo docker run -d -p 8080:80 --name alc-challenge udoyen/challenge-image
gcloud compute firewall-rules create docker-rule --action=ALLOW --direction=INGRESS --rules=tcp:8080 --source-ranges=""
sudo docker container stop alc-challenge
  1. Set up the instance to allow pushing of docker images to google container registry:
gcloud compute instances stop challenge-vm --zone=us-central1-a
gcloud compute instances set-service-account challenge-vm --scopes=storage-rw --zone=us-central1-a
gcloud compute instances start challenge-vm
gcloud auth configure-docker
sudo chown $USER:$USER ~/.docker/config.json
curl -O
tar xvf google-cloud-sdk-267.0.0-linux-x86_64.tar.gz
cd google-cloud-sdk && ./
sudo rm -rf /usr/lib/google-cloud-sdk
gcloud components install docker-credential-gcr
gcloud auth print-access-token | sudo docker login -u oauth2accesstoken --password-stdin
gcloud compute firewall-rules create docker-rule-out --allow=tcp --direction=EGRESS --destination-ranges=""
docker login --username <your_username>
sudo docker tag udoyen/challenge-image
sudo docker push
gcloud beta container --project "spikey-bigtable-new" clusters create "challenge-cluster" --zone "us-central1-a"  --machine-type "g1-small" --num-nodes "3"
gcloud components install kubectl
gcloud compute --project=spikey-bigtable-new firewall-rules create kubernetes-deploy-out --direction=EGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8080 --destination-ranges=
kubectl create deployment challenge-deploy
kubectl expose deployment challenge-deploy --type=LoadBalancer --port 80 --target-port 80



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
george udosen

george udosen


DevOps | FullStack developer | Python::Flask | GCP Cloud Certified | AWS & AZURE Cloud Savy | Linux Sysadmin | Google IT Support