Last active
October 11, 2020 19:19
-
-
Save themagellanic/de3ae15d8853adfb550691a469f0cf47 to your computer and use it in GitHub Desktop.
Create an instance VM and expand it to Kubernetes to host 2 VM instances and then add HTTP Load Balancer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 1: Create a project jumphost instance | |
We will use this instance to perform maintenance for the project. | |
Make sure you: | |
1.name the instance nucleus-jumphost | |
2.use the machine type of f1-micro | |
3.use the default image type (Debian Linux) | |
$gcloud compute instances create nucleus-jumphost --machine-type f1-micro --zone us-east1-b | |
_________________________________________________________________________________________________ | |
Before going on task 2 set the default zone to avoid writing --zone flag in every command- | |
$gcloud config set compute/zone us-east1-b | |
__________________________________________________________________________________________________ | |
Task 2: Create a Kubernetes service cluster | |
1.Create a cluster (in the us-east1-b zone) to host the service. | |
$gcloud container clusters create nucleus-jumphost-webserver | |
______________________________________________________________________ | |
Before proceeding get credentials for the cluster | |
$gcloud container clusters get-credentials nucleus-jumphost-webserver | |
_______________________________________________________________________ | |
2.Use the Docker container hello-app (`gcr.io/google-samples/hello-app:2.0`) as a place holder, | |
the team will replace the container with their own work later. | |
$kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0 | |
_______________________________________________________________________ | |
3.Expose the app on port 8080 | |
$kubectl expose deployment hello-server --type=LoadBalancer --port 8080 | |
$kubectl get service // to check your service is working or not | |
---------------------------------------------------------------------------------------------------------------------------------- | |
Task3 | |
________________________________________________________________ | |
cat << EOF > startup.sh | |
#! /bin/bash | |
apt-get update | |
apt-get install -y nginx | |
service nginx start | |
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html | |
EOF | |
__________________________________________________________________ | |
1.Create an instance template | |
gcloud compute instance-templates create nginx-template \ | |
--metadata-from-file startup-script=startup.sh | |
___________________________________________________________________ | |
2.Create a target pool | |
gcloud compute target-pools create nginx-pool | |
____________________________________________________________________ | |
3.Create a managed instance group | |
gcloud compute instance-groups managed create nginx-group \ | |
--base-instance-name nginx \ | |
--size 2 \ | |
--template nginx-template \ | |
--target-pool nginx-pool | |
_____________________________________________________________________ | |
List the compute engine instances and you should see all of the instances created: | |
gcloud compute instances list | |
4.Create a firewall rule to allow traffic (80/tcp) | |
gcloud compute firewall-rules create www-firewall --allow tcp:80 | |
______________________________________________________________________ | |
5.Create a health check | |
gcloud compute http-health-checks create http-basic-check | |
______________________________________________________________________ | |
6.Create a backend service and attach the manged instance group | |
gcloud compute instance-groups managed \ | |
set-named-ports nginx-group \ | |
--named-ports http:80 | |
gcloud compute backend-services create nginx-backend \ | |
--protocol HTTP --http-health-checks http-basic-check --global | |
gcloud compute backend-services add-backend nginx-backend \ | |
--instance-group nginx-group \ | |
--instance-group-zone us-east1-b \ | |
--global | |
______________________________________________________________ | |
7.Create a URL map and target HTTP proxy to route requests to your URL map | |
gcloud compute url-maps create web-map \ | |
--default-service nginx-backend | |
gcloud compute target-http-proxies create http-lb-proxy \ | |
--url-map web-map | |
______________________________________________________________________ | |
8.Create a forwarding rule | |
gcloud compute forwarding-rules create http-content-rule \ | |
--global \ | |
--target-http-proxy http-lb-proxy \ | |
--ports 80 | |
gcloud compute forwarding-rules list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment