JHipster Application with 4 microservices
sudo apt update
sudo apt install openjdk-8-jdk
sudo apt-get update -y
sudo apt-get install -y apt-transport-https
sudo su -
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update -y
swapoff -a
sed -i '/swap / s/^\(.*\)$/#\1/g' /etc/fstab
Enable ip tables because master machine and kubernetes cluster machine will talk to each other and also pod to pod commuication will happen with this
modprobe br_netfilter
sysctl -p
sudo sysctl net.bridge.bridge-nf-call-iptables=1
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
systemctl daemon-reload
systemctl start kubelet
systemctl enable kubelet.service
gcloud auth login
gcloud config set project payment-platform-204588
gcloud container clusters create final-cluster --zone us-central1-a --num-nodes 4 --machine-type n1-standard-2
gcloud container clusters get-credentials final-cluster --zone us-central1-a
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user="[email protected]"
kubectl get pods -n avengers
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins
systemctl status jenkins (Check Status if installed properly or not)
sudo systemctl restart jenkins
http://your_ip_or_domain:8080
sudo cat /var/lib/jenkins/secrets/initialAdminPassword (Location to Password)
Install suggested Plugins```
curl -fsSL get.docker.com | /bin/bash
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
1. Install Helm ( https://github.com/helm/helm )
https://raw.githubusercontent.com/helm/helm/master/scripts/get
wget https://github.com/istio/istio/releases/download/1.0.6/istio-1.0.6-linux.tar.gz
tar xvfz istio-1.0.6-linux.tar.gz
cd istio-1.0.6
kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml
kubectl apply -f install/kubernetes/istio-demo.yaml --as=admin --as-group=system:masters
kubectl get services -n istio-system ( 34.67.38.135 )
kubectl apply -f configuration.yaml (Find it in the enclosed folder)
GCP -> Kubernetes Engine -> Application -> Elastic GKE logging -> Create New Namespace -> Create
Change the ip to your ip in this file
kubectl apply -f kibana-gateway.yml
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install nodejs
npm install -g generator-jhipster
npm install -g yo ( Optional )
script.jh ( Find it in the enclosed folder )
./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/<Image Name>
cd /home/shagunbandi/project/ui && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/ui && cd /home/shagunbandi/project/organization && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/organization && cd /home/shagunbandi/project/leave && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/leave && cd /home/shagunbandi/project/meeting && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/meeting && cd /home/shagunbandi/project/notification && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=shagunbandi/notification
gcloud container clusters get-credentials final-cluster --zone us-central1-a
cd kubernetes
kubectl apply -f namespace.yml
kubectl label namespace avengers istio-injection=enabled --overwrite=true
kubectl apply -f ui/
kubectl apply -f organization/
kubectl apply -f leave/
kubectl apply -f meeting/
kubectl apply -f notification/
kubectl apply -f istio/
kubectl get pods -n avengers
If everything is Running try http://ui.avengers.34.67.38.135.nip.io
Add Plugin
Manage Jenkins -> Manage Plugins -> Available -> Kubernetes Continuous Deploy Plugin
Add Maven
Manage Jenkins -> Global Tool Configuration -> Add Maven
Add Git Credentials
Credentials -> Add Credentials (next to global) -> Username With Password (Kind), Username and Password, ID = GIT_CRED
Add Docker Password Secret File
Credentials -> Add Credentials -> Secret Text (Kind) -> ID = DOCKER_CRED
Gateway - http://ui.avengers.34.67.38.135.nip.io
Zipkin - http://zipkin.istio-system.34.67.38.135.nip.io
Grafana - http://grafana.istio-system.34.67.38.135.nip.io
Kiali - http://kiali.istio-system.34.67.38.135.nip.io
sudo chmod 777 /var/run/docker.sock
docker login -u <username>
kubectl get pods
kubectl get pods -n <namespace>
kubectl delete pods <pod-name> -n <namespace>
Make sure you are the owner of the project or have enough permissions. You can check that by going to IAM roles.
spec > strategy > type: Recreate
spec > template > containers > imagePullPolicy: Always
This is the pipeline script. change the url, DOCKER_CRED, Docker Username, tagname, project name accordingly.
pipeline {
agent any
environment {
GIT_URL = "https://github.com/manvinirwal/final-jhipster"
DOCKER_BASE = "shagunbandi"
BRIDGE = "bridge"
CLUSTER_NAME = "final-cluster"
PROJECT_ID = "payment-platform-204588"
NAMESPACE = "avengers"
COMMIT_ID = find_commit_id()
}
stages {
stage("Git clone"){
steps {
git credentialsId: 'GIT_CRED_MANVI', url: "${GIT_URL}"
}
}
stage("Maven Clean, Build, Docker Push for UI"){
agent { label 'master' }
steps{
withCredentials([string(credentialsId: 'DOCKER_CRED', variable: 'DOCKER_CRED')]) {
sh "docker login -u ${DOCKER_BASE} -p ${DOCKER_CRED}"
}
sh "cd ui && ./mvnw -ntp -Pprod verify jib:build -Djib.to.image=${DOCKER_BASE}/ui:${env.COMMIT_ID} && cd .."
sh 'cd ui && npm run e2e && cd..'
}
}
stage("Deploy"){
agent { label 'master' }
steps {
sh "gcloud container clusters get-credentials ${CLUSTER_NAME} --zone us-central1-a --project ${PROJECT_ID}"
sh "cd kubernetes && sh kubectl-apply.sh && cd .."
sh "kubectl set image deployment.v1.apps/ui ui-app=${DOCKER_BASE}/ui:${env.COMMIT_ID} -n=${NAMESPACE}"
}
}
}
}
def find_commit_id() {
node('master') {
sh "git rev-parse HEAD > .git/commit-id"
return readFile('.git/commit-id').trim()
}
}