-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcreate-cert-host.sh
executable file
·38 lines (31 loc) · 1.02 KB
/
create-cert-host.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
[[ "TRACE" ]] && set -x
# e.g. ./execute.sh -h 192.168.0.23 -e LOCAL
while [ $# -gt 0 ]; do
case "$1" in
-h | --host)
shift
APP_HOST=$1
;;
-n | --namespace)
shift
NAMESPACE=$1
;;
esac
shift
done
if [ -z "$APP_HOST" ]; then
echo "Please provide host name"
exit 1
elif [ -z "$NAMESPACE" ]; then
echo "Please provide namespace"
exit 1
fi
CERT_NAME=${APP_HOST//./-}
#below would create user named ingress with group assigned as ingress:masters
openssl genrsa -out "${APP_HOST}".key 4096
openssl req -new -key "${APP_HOST}".key -out "${APP_HOST}".csr -subj "/CN=${APP_HOST}" \
-addext "subjectAltName = DNS:${APP_HOST}"
openssl x509 -req -in "${APP_HOST}".csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out "${APP_HOST}".crt -days 7200
kubectl create secret tls "${CERT_NAME}"-tls --key "${APP_HOST}".key --cert "${APP_HOST}".crt -n "${NAMESPACE}"
rm "${APP_HOST}".key "${APP_HOST}".crt "${APP_HOST}".csr