coins-demo/contrib/firstboot.sh

69 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/bash
2020-07-31 13:32:43 +00:00
bootflag='/.manufactured'
2020-07-31 11:33:22 +00:00
groot='/opt/coins-demo'
k8sDemoWA () {
2020-07-31 15:04:12 +00:00
printf "\033c"
2020-07-31 11:33:22 +00:00
echo 'Disabling swap space...'
sync && swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab
2020-07-31 15:04:12 +00:00
export KUBECONFIG=/root/.kube/config
2020-07-31 11:33:22 +00:00
}
2020-07-31 14:44:43 +00:00
k8sDeploy () {
2020-07-31 11:33:22 +00:00
echo 'Installing K8s...'
cd ${groot}/contrib/ansible && \
ansible-playbook bootstrap-node.yml && \
ansible-playbook init-cluster.yml
2020-08-01 23:06:44 +00:00
# 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
2020-08-01 15:51:41 +00:00
}
InstallCSI () {
helm repo add rimusz https://charts.rimusz.net
helm install rimusz/hostpath-provisioner --generate-name
2020-08-01 14:33:34 +00:00
}
2020-08-01 15:03:57 +00:00
InstallRegistry () {
2020-08-01 19:09:32 +00:00
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm install registry stable/docker-registry \
--set ingress.enabled=true \
2020-08-01 23:04:33 +00:00
--set ingress.hosts[0]="registry.k8s-demo.ix.gs"
2020-08-01 15:03:57 +00:00
}
2020-08-01 15:51:41 +00:00
InstallPGSQL () {
helm repo add bitnami https://charts.bitnami.com/bitnami
2020-08-01 16:13:45 +00:00
helm install db bitnami/postgresql \
2020-08-01 15:51:41 +00:00
--set persistence.storageClass=hostpath \
2020-08-01 16:13:45 +00:00
--set persistence.size=1Gi
2020-08-01 15:51:41 +00:00
}
2020-08-01 14:33:34 +00:00
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
2020-08-01 15:51:41 +00:00
# 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)"
2020-07-31 11:33:22 +00:00
}
2020-08-01 21:38:16 +00:00
InstallApp () {
cd ${groot}
2020-08-01 23:04:33 +00:00
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 && \
2020-08-01 21:39:49 +00:00
werf deploy --env production --set 'DBPwd=$(kubectl get secret db-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)'
2020-08-01 21:38:16 +00:00
}
2020-07-31 13:32:43 +00:00
if [ ! -f ${bootflag} ]; then
touch ${bootflag}
k8sDemoWA;
2020-07-31 14:44:43 +00:00
k8sDeploy;
2020-08-01 15:51:41 +00:00
InstallCSI;
2020-08-01 14:33:34 +00:00
InstallIngress;
2020-08-01 15:51:41 +00:00
InstallRegistry;
InstallPGSQL;
2020-07-31 13:32:43 +00:00
fi