coredns-deployment/kubernetes/rollback.sh
Julian V. Modesto a6c087005f deploy.sh and rollback.sh fixes (#99)
* Don't overwrite KUBECONFIG.

kubectl already knows to look in $HOME/.kube or use $KUBECONFIG.

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable

* Use $DIR instead of pwd.

https://stackoverflow.com/a/246128/1881379

* chmod +x kubernetes/rollback.sh
2018-10-16 11:14:03 -04:00

48 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# Roll back kube-dns to the cluster which has CoreDNS installed.
set -eo pipefail
show_help () {
cat << USAGE
usage: $0 [ -i DNS-IP ] [ -d CLUSTER-DOMAIN ]
-i : Specify the cluster DNS IP address. If not specificed, the IP address of
the existing "kube-dns" service is used, if present.
-d : Specify the Cluster Domain. Default is "cluster.local"
USAGE
exit 0
}
# Simple Defaults
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
CLUSTER_DOMAIN=cluster.local
YAML_TEMPLATE="$DIR/kube-dns.yaml.sed"
curl -L https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/dns/kube-dns/kube-dns.yaml.base > "$YAML_TEMPLATE"
# Get Opts
while getopts "hi:d:" opt; do
case "$opt" in
h) show_help
;;
i) CLUSTER_DNS_IP=$OPTARG
;;
d) CLUSTER_DOMAIN=$OPTARG
;;
esac
done
if [[ -z $CLUSTER_DNS_IP ]]; then
# Default IP to kube-dns IP
CLUSTER_DNS_IP=$(kubectl get service --namespace kube-system kube-dns -o jsonpath="{.spec.clusterIP}")
if [ $? -ne 0 ]; then
>&2 echo "Error! The IP address for DNS service couldn't be determined automatically. Please specify the DNS-IP with the '-i' option."
exit 2
fi
fi
sed -e s/__PILLAR__DNS__SERVER__/${CLUSTER_DNS_IP}/g -e s/__PILLAR__DNS__DOMAIN__/${CLUSTER_DOMAIN}/g ${YAML_TEMPLATE}