Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created February 1, 2023 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vfarcic/5c39b866a77c33a2863d67deb5d24682 to your computer and use it in GitHub Desktop.
Save vfarcic/5c39b866a77c33a2863d67deb5d24682 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/5c39b866a77c33a2863d67deb5d24682
####################################################
# What Is Kubernetes Ingress And How Does It Work? #
# https://youtu.be/HqTEHVlQpwY #
####################################################
# Additional Info:
# - Contour: https://projectcontour.io
#########
# Setup #
#########
# Create a Kubernetes cluster (NOT a local one like Minikube, Docker Desktop, Rancher Desktop, etc.)
git clone https://github.com/vfarcic/contour-demo
cd contour-demo
kubectl create namespace demo
kubectl apply \
--filename https://projectcontour.io/quickstart/contour-gateway-provisioner.yaml
kubectl apply --filename gateway.yaml
# If NOT EKS
export INGRESS_HOST=$(kubectl --namespace projectcontour \
get service envoy-contour \
--output jsonpath="{.status.loadBalancer.ingress[0].ip}")
# If EKS
export INGRESS_HOSTNAME=$(kubectl --namespace projectcontour \
get service envoy-contour \
--output jsonpath="{.status.loadBalancer.ingress[0].hostname}")
# If EKS
export INGRESS_HOST=$(dig +short $INGRESS_HOSTNAME)
echo $INGRESS_HOST
# Repeat the `export` command(s) if the output is empty.
# If the output contains more than one IP, wait for a while longer, and repeat the `export` commands.
# If the output continues having more than one IP, choose one of them and execute `export INGRESS_HOST=[...]` with `[...]` being the selected IP.
# Install `yq` from https://github.com/mikefarah/yq if you do not have it already
yq --inplace \
".spec.rules[0].host = \"silly-demo.$INGRESS_HOST.nip.io\"" \
k8s/ingress.yaml
yq --inplace \
".spec.hostnames[0] = \"silly-demo2.$INGRESS_HOST.nip.io\"" \
k8s/route.yaml
################################
# How Kubernetes Ingress Works #
################################
kubectl --namespace demo apply --filename k8s
curl "http://silly-demo.$INGRESS_HOST.nip.io"
kubectl --namespace projectcontour get pods
kubectl --namespace projectcontour get services
cat k8s/ingress.yaml
cat k8s/service.yaml
cat k8s/deployment.yaml
kubectl --namespace demo get pods
###########
# Destroy #
###########
# Destroy or reset the cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment