#!/bin/bash
clear

tput setaf 5
echo -e "\n \n*******************************************************************************************************************"
echo -e "Deploying Bitnami NGINX"
echo -e "*******************************************************************************************************************"

tput setaf 6
echo -e "\n \n*******************************************************************************************************************"
echo -e "Creting Demo namespace"
echo -e "*******************************************************************************************************************"
tput setaf 2
kubectl create ns demo

tput setaf 6
echo -e "\n \n*******************************************************************************************************************"
echo -e "Deploying NGINX and exposing NGINX"
echo -e "*******************************************************************************************************************"
tput setaf 2
kubectl run nginx-hack --image=bitnami/nginx -n demo
kubectl expose pod nginx-hack -n demo --port=80 --target-port=8080

tput setaf 6
echo -e "\n \n*******************************************************************************************************************"
echo -e "Creating Ingress rule for the NGINX server"
echo -e "*******************************************************************************************************************"
tput setaf 2
export hostip=$(hostname  -I | cut -f1 -d ' ')
envsubst < nginx-ingress.yaml | kubectl create -f - --namespace demo

tput setaf 6
echo -e "\n \n*******************************************************************************************************************"
echo -e "Ingress Rule has been created for NGINX: demo-hack.$hostip.nip.io"
echo -e "*******************************************************************************************************************"
tput setaf 2


tput setaf 2


echo -e "\n\n"
