Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start server from HOME dir, sleep to prevent rate limiting on prod API #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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


1 change: 0 additions & 1 deletion kube-nginx-letsencrypt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
14 changes: 12 additions & 2 deletions kube-nginx-letsencrypt/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand Down