-
Notifications
You must be signed in to change notification settings - Fork 2
/
nginx-update-cert.sh
executable file
·61 lines (51 loc) · 1.74 KB
/
nginx-update-cert.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
CERT_FILE=https1.cert
KEY_FILE=https1.key
if [[ -z "$NAMESPACE" ]]; then
echo "Define NAMESPACE environment variable!"
exit 1
fi
if [[ -z "$APP_INSTANCE_NAME" ]]; then
echo "Define APP_INSTANCE_NAME environment variable!"
exit 1
fi
if [[ -f $CERT_FILE ]]; then
echo "Using $CERT_FILE as a certificate."
else
echo "File $CERT_FILE doesn't exist. Run nginx-create-key.sh script"
exit 1
fi
if [[ -f $KEY_FILE ]]; then
echo "Using $KEY_FILE as a certificate."
else
echo "File $KEY_FILE doesn't exist. Run nginx-create-key.sh script"
exit 1
fi
# using --dry-run and then using kubectl apply... to avoid errors
# while invoking kubectl create for the secret that already exist
kubectl --namespace $NAMESPACE create secret generic $APP_INSTANCE_NAME-nginx-secret \
--from-file=$CERT_FILE --from-file=$KEY_FILE \
--dry-run -o yaml | kubectl apply -f -
PODS=$(kubectl get pods -l app.kubernetes.io/name=$APP_INSTANCE_NAME --namespace $NAMESPACE | awk 'FNR>1 {print $1}')
TIMEOUT=60
for i in ${PODS[@]}; do
echo "Deleting Pod: $i..."
kubectl delete pod $i --namespace $NAMESPACE
echo "Sleeping for $TIMEOUT seconds..."
sleep $TIMEOUT
done