• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

website

Static Website on GKE

December 25, 2019

Here’s how to run your web application on Google Kubernetes Engine.

Create a Dockerfile. Place your web pages in the public-html directory.

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/

Build a container image for Google Container Registry (GCR).

# set your project
export PROJECT_ID=[project_id]
# build a container image
docker build -t gcr.io/${PROJECT_ID}/your-app:v1 .
# verify docker images
docker images

# set your project export PROJECT_ID=[project_id] # build a container image docker build -t gcr.io/${PROJECT_ID}/your-app:v1 . # verify docker images docker images

Upload the container image to GCR.

# authenticate
gcloud auth configure-docker
# upload image
docker push gcr.io/${PROJECT_ID}/your-app:v1

# authenticate gcloud auth configure-docker # upload image docker push gcr.io/${PROJECT_ID}/your-app:v1

Create a container GKE cluster.

# create cluster
gcloud container clusters create your-app-cluster \
--num-nodes=2
# check clusters
gcloud compute instances list

# create cluster gcloud container clusters create your-app-cluster \ --num-nodes=2 # check clusters gcloud compute instances list

Deploy your web application.

# create deployment
kubectl create deployment your-app \
--image=gcr.io/${PROJECT_ID}/your-app:v1
# see the pods
kubectl get pods

# create deployment kubectl create deployment your-app \ --image=gcr.io/${PROJECT_ID}/your-app:v1 # see the pods kubectl get pods

Expose your application to the Internet.

# expose your application
kubectl expose deployment your-app \
--type=LoadBalancer \
--port 80 \
--target-port 80
# get the external ip address
kubectl get service

# expose your application kubectl expose deployment your-app \ --type=LoadBalancer \ --port 80 \ --target-port 80 # get the external ip address kubectl get service

Scale your application.

# scale to 3 replicas
kubectl scale deployment your-app --replicas=3
# display the replicas
kubectl get deployment your-app

# scale to 3 replicas kubectl scale deployment your-app --replicas=3 # display the replicas kubectl get deployment your-app

Cleanup.

kubectl delete service your-app
gcloud container clusters delete your-app-cluster

kubectl delete service your-app gcloud container clusters delete your-app-cluster

Filed Under: Cloud Tagged With: container, deployment, docker, gcp, gcr, gke, kubectl, kubernetes, scale, static, website

Run Shell Script From Your Website

September 10, 2019

Here’s how to run a shell script from your website. You’ll need 2 files.

Here’s the contents of foo.php. Wrap your output with ‘pre’ for better formatting.

<?php
$output = shell_exec('/var/www/html/bar.sh 2>&1');
echo "$output";

<?php $output = shell_exec('/var/www/html/bar.sh 2>&1'); echo "$output";

Here’s the content of bar.sh. Output will be displayed on web page.

#!/bin/bash
now="$(date +'%y%m%d')"
echo $now
aws s3 ls

#!/bin/bash now="$(date +'%y%m%d')" echo $now aws s3 ls

Filed Under: Cloud, Linux Tagged With: bash, php, run, script, shell, website

Run Jekyll in Background

August 7, 2019

Jekyll is a static website generator you can use for developing simple websites. If you are running Jekyll on your desktop, you can view your static website by running a local server. If you want the leave the web server up and running in the background all the time, you can run this command instead.

# normally you run this command
jekyll serve
# running it in the background
jekyll serve > /dev/null 2>&1 &
# add incremental which builds only deltas
jekyll serve --incremental > /dev/null 2>&1 &

# normally you run this command jekyll serve # running it in the background jekyll serve > /dev/null 2>&1 & # add incremental which builds only deltas jekyll serve --incremental > /dev/null 2>&1 &

To kill the server, run the following.

# find jekyll server process
ps -ef | grep jekyll
# substitute pid# with process id
kill -9 pid#

# find jekyll server process ps -ef | grep jekyll # substitute pid# with process id kill -9 pid#

Filed Under: Cloud, Linux Tagged With: generator, jekyll, serve, static, website

  • Home
  • About
  • Archives

Copyright © 2023