coins-demo/contrib/firstboot.sh
2020-08-01 20:45:08 +02:00

59 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
bootflag='/.manufactured'
groot='/opt/coins-demo'
k8sDemoWA () {
printf "\033c"
echo 'Disabling swap space...'
sync && swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab
export KUBECONFIG=/root/.kube/config
}
k8sDeploy () {
echo 'Installing K8s...'
cd ${groot}/contrib/ansible && \
ansible-playbook bootstrap-node.yml && \
ansible-playbook init-cluster.yml
# Sometimes it's still not ready on this stage, let's check it just to be sure
while true ; do
echo "Waiting for node up..."
result=$(kubectl get nodes|awk '{print $2}'| tail -1| grep -nE '^Ready')
if [ -z "$result" ] ; then
break
fi
sleep 10
done
cd ${groot}/contrib
}
InstallCSI () {
helm repo add rimusz https://charts.rimusz.net
helm install rimusz/hostpath-provisioner --generate-name
}
InstallRegistry () {
echo ToDo
}
InstallPGSQL () {
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install db bitnami/postgresql \
--set persistence.storageClass=hostpath \
--set persistence.size=1Gi
export POSTGRES_PASSWORD=$(kubectl get secret db-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
}
InstallIngress () {
# Allow scheduling on our master node
kubectl taint nodes k8s-demo node-role.kubernetes.io/master-
# Installing Ingress
helm repo add nginx-stable https://helm.nginx.com/stable && \
helm install nginx-stable/nginx-ingress --namespace kube-system --generate-name --set rbac.create=true
# Fix external IP for LB...
kubectl patch svc $(kubectl get svc -n kube-system|grep nginx-ingress|awk '{print $1}') -n kube-system --patch "$(cat ${groot}/contrib/ymls/ingress.fix.yaml)"
}
if [ ! -f ${bootflag} ]; then
touch ${bootflag}
k8sDemoWA;
k8sDeploy;
InstallCSI;
InstallIngress;
InstallRegistry;
InstallPGSQL;
fi