coins-demo/contrib/firstboot.sh
2020-08-02 01:04:33 +02:00

68 lines
2.3 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
}
InstallCSI () {
helm repo add rimusz https://charts.rimusz.net
helm install rimusz/hostpath-provisioner --generate-name
}
InstallRegistry () {
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm install registry stable/docker-registry \
--set ingress.enabled=true \
--set ingress.hosts[0]="registry.k8s-demo.ix.gs"
}
InstallPGSQL () {
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install db bitnami/postgresql \
--set persistence.storageClass=hostpath \
--set persistence.size=1Gi
}
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)"
}
InstallApp () {
cd ${groot}
export WERF_INSECURE_REGISTRY=true
export WERF_IMAGES_REPO='http://registry.k8s-demo.vm/gtd'
werf build --stages-storage :local && \
werf publish --stages-storage :local --tag-git-branch master && \
werf deploy --env production --set 'DBPwd=$(kubectl get secret db-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)'
}
if [ ! -f ${bootflag} ]; then
touch ${bootflag}
k8sDemoWA;
k8sDeploy;
InstallCSI;
InstallIngress;
InstallRegistry;
InstallPGSQL;
fi