diff --git a/README.md b/README.md index 388ec5e..ef1bd47 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # Kubernetes + Let's Encrypt Automatic Cert Generation Demo for how to automatically create https certs on Kubernetes using Let's encrypt + + +docker build -t gcr.io/dht-2718/letsencrypt:testserver . +gcloud docker -- push gcr.io/dht-2718/letsencrypt:testserver + +http://frameworthyfilms.com/.well-known/acme-challenge/blank + +POD=$(kubectl get pods | grep nginx | awk '{print $1}') +kubectl exec $POD -it bash +apt-get update && apt-get install curl -qq -y # Terrible, I know +curl letsencrypt # Name of the service + + +docker build -t gcr.io/dht-2718/letsencrypt:getcreds . +gcloud docker -- push gcr.io/dht-2718/letsencrypt:getcreds + + diff --git a/kube-nginx-letsencrypt/Dockerfile b/kube-nginx-letsencrypt/Dockerfile index 5bebfa7..72dab4d 100644 --- a/kube-nginx-letsencrypt/Dockerfile +++ b/kube-nginx-letsencrypt/Dockerfile @@ -5,7 +5,6 @@ RUN dnf install certbot -y && dnf clean all RUN mkdir /etc/letsencrypt COPY secret-patch-template.json / -COPY deployment-patch-template.json / COPY entrypoint.sh / CMD ["/entrypoint.sh"] diff --git a/kube-nginx-letsencrypt/entrypoint.sh b/kube-nginx-letsencrypt/entrypoint.sh index f7286b9..e4619bc 100755 --- a/kube-nginx-letsencrypt/entrypoint.sh +++ b/kube-nginx-letsencrypt/entrypoint.sh @@ -15,16 +15,26 @@ NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) echo "Current Kubernetes namespce: $NAMESPACE" echo "Starting HTTP server..." +mkdir $HOME/.well-known +mkdir $HOME/.well-known/acme-challenge +echo "This is some text" > $HOME/.well-known/acme-challenge/blank +cd $HOME python -m SimpleHTTPServer 80 & PID=$! +echo "sleeping 1m" +sleep 1m echo "Starting certbot..." certbot certonly --webroot -w $HOME -n --agree-tos --email ${EMAIL} --no-self-upgrade -d ${DOMAINS} -kill $PID echo "Certbot finished. Killing http server..." +ls $HOME +ls $HOME/.well-known +ls $HOME/.well-known/acme-challenge + echo "Finiding certs. Exiting if certs are not found ..." CERTPATH=/etc/letsencrypt/live/$(echo $DOMAINS | cut -f1 -d',') -ls $CERTPATH || exit 1 +ls $CERTPATH || (echo "sleeping 60m";sleep 60m; exit 1) +kill $PID echo "Creating update for secret..." cat /secret-patch-template.json | \