Skip to content

Instantly share code, notes, and snippets.

@BarDweller
Last active March 11, 2020 05:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BarDweller/649c0ee9e814b4afefba5b80c34f6002 to your computer and use it in GitHub Desktop.
Save BarDweller/649c0ee9e814b4afefba5b80c34f6002 to your computer and use it in GitHub Desktop.
Minikube setup for local appsody usage...
#!/bin/bash
K8S_VERSION=v1.15.4
check_version()
{
version=$(echo $1 | sed -n 's/^[^0-9]*\([0-9.]\{1,\}\).*$/\1/p' )
minimum=$2
winner=$(echo -e "$version\n$minimum" | sed '/^$/d' | sort -t . -k1,1n -k2,2n -k3,3n | tail -1)
if [ "$winner" = "$version" ]; then
echo -e " ${GREEN}OK${NO_COLOR}: $1"
else
echo -e " ${RED}BACKLEVEL${NO_COLOR}: $1"
fi
[[ "$winner" = "$version" ]] && return 0
return 1
}
echo "Checking versions for tooling..."
echo ""
echo "Checking Minikube version.."
VERSION=$(minikube version | head -n 1)
if [ $? != 0 ]; then echo "minikube not found, please install 1.5.2 or above"; exit 1; fi
check_version "${VERSION}" 1.5.2
if [ $? != 0 ]; then echo "bad version, exiting"; exit 1; fi
echo "Checking kubectl version.."
VERSION=$(kubectl version --client --short)
if [ $? != 0 ]; then echo "kubectl not found, please install 1.15.4 or above"; exit 1; fi
check_version "${VERSION}" 1.15.4
if [ $? != 0 ]; then echo "bad version, exiting"; exit 1; fi
echo "Checking helm version.."
VERSION=$(helm version --client --short)
if [ $? != 0 ]; then echo "helm not found, please install 2.16.1 or above"; exit 1; fi
check_version "${VERSION}" 2.16.1
if [ $? != 0 ]; then echo "bad version, exiting"; exit 1; fi
echo "Checking appsody version.."
VERSION=$(appsody version)
if [ $? != 0 ]; then echo "appsody not found, please install 0.4.10 or above"; exit 1; fi
check_version "${VERSION}" 0.4.10
if [ $? != 0 ]; then
if [ "${VERSION}" == "0.0.0" ]; then
echo "****************************************************************"
echo "* INTERNAL BUILD OF APPSODY DETECTED. This is NOT recommended. *"
echo "****************************************************************"
echo "Allowing continue, but any issues should be tested with a release build."
else
echo "bad version, exiting"
exit 1
fi
fi
echo "Installing Minikube..."
echo ""
# fix restart upgrading the cluster...
minikube config set kubernetes-version ${K8S_VERSION}
# launch k8s.
minikube start --kubernetes-version ${K8S_VERSION}
# waiting for node(s) to be ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done
# waiting for kube-addon-manager to be ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lcomponent=kube-addon-manager -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-addon-manager to be available"; kubectl get pods --all-namespaces; done
# waiting for kube-dns to be ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lk8s-app=kube-dns -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-dns to be available"; kubectl get pods --all-namespaces; done
echo "Installing Helm..."
echo ""
# create rbac-config.yaml
cat > rbac-config.yaml <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
EOF
# apply tiller roles to cluster.
kubectl apply -f rbac-config.yaml
helm init --service-account tiller --history-max 200
# waiting for helm tiller to be ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lapp=helm -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for tiller to be available"; kubectl get pods --all-namespaces; done
echo "Installing Prometheus Operator..."
echo ""
# install prometheus operator
helm install --name miniprometheus --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false stable/prometheus-operator
# wait for grafana to be ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get pods -lapp=grafana -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for grafana to be available"; kubectl get pods --all-namespaces; done
echo "Installing Registry..."
echo ""
# enable registry
minikube addons enable registry
# wait for registry
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lkubernetes.io/minikube-addons=registry,actual-registry=true -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for registry to be available"; kubectl get pods --all-namespaces; done
echo "Exposing Services via PortForwards..."
echo ""
# port forward registry
kubectl port-forward -n kube-system $(kubectl -n kube-system get pods -lkubernetes.io/minikube-addons=registry,actual-registry=true -o jsonpath='{.items[0].metadata.name}') 5000:5000 &
# port forward dashboard.
kubectl port-forward -n kubernetes-dashboard $(kubectl get pods -n kubernetes-dashboard -lk8s-app=kubernetes-dashboard -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 9090:9090 &
# port forward grafana
kubectl port-forward $(kubectl get pods -lapp=grafana -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 3000:3000 &
# port forward prometheus
kubectl port-forward -n default prometheus-miniprometheus-prometheus-prometheus-0 --address 0.0.0.0 9091:9090 &
echo "Done."
echo "Kubernetes dashboard is on http://127.0.0.1:9090/"
echo "Prometheus dashboard is at http://127.0.0.1:9091"
echo "Grafana is on http://127.0.0.1:3000 admin/prom-operator (or check the grafana secret & decode yourself"
echo "Docker registry available as localhost:5000"
echo "Deploy appsody apps with appsody deploy --tag localhost:5000/orgname/appname:latest --push"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment