Run static website on Kubernetes

Assuming kubectl is configured. This is how to run default nginx site on Kubernetes.

Simple setup = load balancer/no ingress

In this example we don’t use an ingress. We just expose the static website behind a loadbalancer, so the static website gets its own public IP.

Using an ingress would allow us to run many websites behind a single public IP.

# Create deployment
kubectl create deployment static-site \
  --image=nginx:alpine

# Expose site
kubectl expose deployment static-site \
  --type=LoadBalancer \
  --port=80

# Get public IP (wait until EXTERNAL-IP appears)
kubectl get svc static-site

# View the site
curl http://EXTERNAL-IP

# Clean up
kubectl delete service static-site
kubectl delete deployment static-site

Note: on upcloud, the external IP shown will not be a IPv4 address. Instead it will be a domain name, e.g. lb-0a896a85a2fb48aba42944f50b41377a-1.upcloudlb.com. You can of course ping the domain and get the IP address.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.