Capstone Project - Health Care
Capstone Project - Health Care
# apt-get update
# apt-get install awscli -y
# aws configure
Give the valid access key
Give the valid secret key
Press enter, no need to give any region and format
option.
}
resource "aws_vpc" "my-vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "my-vpc"
}
vpc_id = aws_vpc.my-vpc.id
cidr_block = "10.0.1.0/24"
depends_on = [aws_vpc.my-vpc]
map_public_ip_on_launch = true
tags = {
Name = "my-subnet"
}
}
route_table_id = aws_route_table.my-route-table.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
variable "sg_ports" {
type = list(number)
default = [8080,80,22,443]
}
resource "aws_security_group" "my-sg" {
name = "sg_rule"
vpc_id = aws_vpc.my-vpc.id
dynamic "ingress" {
for_each = var.sg_ports
iterator = port
content{
from_port = port.value
to_port = port.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port =0
to_port =0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "myec2" {
ami = "ami-0166fe664262f664c"
instance_type = "t2.medium"
key_name = "web-key"
subnet_id = aws_subnet.subnet-1.id
security_groups = [aws_security_group.my-sg.id]
tags = {
Name = "Terrafrom-EC2"
}
provisioner "remote-exec" {
connection {
type = "ssh"
user = "ubuntu"
private_key =
tls_private_key.mykey.private_key_pem
host = self.public_ip
}
inline = [
"sudo apt update",
"sudo apt install software-properties-common",
"sudo add-apt-repository --yes --update
ppa:ansible/ansible",
"sudo apt install ansible -y"
]
}
}
agent any
tools{
maven 'mymvn'
}
stages{
stage('Clone Repo')
{
steps{
git 'https://github.com/saransh-
vijayvargiya/star-agile-health-care.git'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}
stage('Build Code')
{
steps{
sh 'mvn package'
}
}
}
}
Now click on build to check whether the build is
happening or not.
pipeline{
agent any
tools{
maven 'mymvn'
}
stages{
stage('Clone Repo')
{
steps{
git 'https://github.com/saransh-vijayvargiya/star-agile-
health-care.git'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}
stage('Build Code')
{
steps{
sh 'mvn package'
}
}
stage('Build Image')
{
steps{
sh 'docker build -t health-care-
project:$BUILD_NUMBER .'
}
}
stage('Push the Image to dockerhub')
{
steps{
withCredentials([string(credentialsId:
'DOCKER_HUB_PASWD', variable: 'DOCKER_HUB_PASWD')])
{
sh 'docker login -u saranshvijayvargiya -p
${DOCKER_HUB_PASWD} '
}
sh 'docker tag health-care-project:$BUILD_NUMBER
saranshvijayvargiya/health-care-project:$BUILD_NUMBER '
sh 'docker push saranshvijayvargiya/health-care-
project:$BUILD_NUMBER'
}
}
}
}
## Install Containerd
sudo wget
https://raw.githubusercontent.com/lerndevops/labs/m
aster/scripts/installContainerd.sh -P /tmp
sudo bash /tmp/installContainerd.sh
sudo systemctl restart containerd.service
### Install kubeadm,kubelet,kubectl
You will install these packages on all of your machines:
kubeadm: the command to bootstrap the cluster.
kubelet: the component that runs on all of the
machines in your cluster and does things like starting
pods and containers.
kubectl: the command line util to talk to your cluster.
# sudo wget
https://raw.githubusercontent.com/lerndevops/labs/m
aster/scripts/installK8S.sh -P /tmp
# sudo bash /tmp/installK8S.sh
## Initialize kubernetes Master Node
# sudo kubeadm init --ignore-preflight-errors=all
Execute the below commands to setup kubectl and
apiserver communication
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf
$HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
## install networking driver --
Weave/flannel/canal/calico etc...
## below installs calico networking driver
kubectl apply -f
https://raw.githubusercontent.com/projectcalico/calico
/v3.24.1/manifests/calico.yaml
## Install kubeadm,kubelet,kubectl
sudo wget
https://raw.githubusercontent.com/lerndevops/labs/m
aster/scripts/installK8S.sh -P /tmp
sudo bash /tmp/installK8S.sh
On Master node:
# kubectl get nodes
stage('Deploy to k8s'){
steps{
kubernetesDeploy configs:
'deploymentservice.yml', kubeConfig: [path: ''],
kubeconfigId: 'k8sconfigpwd', secretName: '', ssh:
[sshCredentialsId: '*', sshServer: ''], textCredentials:
[certificateAuthorityData: '', clientCertificateData: '',
clientKeyData: '', serverUrl: 'https://']
}
}
Note: This is our final pipeline syntax:
pipeline{
agent any
tools{
maven 'mymvn'
}
stages{
stage('Clone Repo')
{
steps{
git 'https://github.com/saransh-
vijayvargiya/star-agile-health-care.git'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}
stage('Build Code')
{
steps{
sh 'mvn clean package'
}
}
stage('Build Image')
{
steps{
sh 'docker build -t health-app .'
}
}
withCredentials([string(credentialsId:
'DOCKER_HUB_PASWD', variable:
'DOCKER_HUB_PASWD')])
{
sh 'docker login -u saranshvijayvargiya -p
${DOCKER_HUB_PASWD} '
}
sh 'docker tag health-app
saranshvijayvargiya/health-app '
sh 'docker push saranshvijayvargiya/health-
app'
}
}
stage('Deploy to k8s'){
steps{
kubernetesDeploy configs:
'deploymentservice.yml', kubeConfig: [path: ''],
kubeconfigId: 'k8sconfigpwd', secretName: '', ssh:
[sshCredentialsId: '*', sshServer: ''], textCredentials:
[certificateAuthorityData: '', clientCertificateData: '',
clientKeyData: '', serverUrl: 'https://']
}
}
}
}
Now save it and click on the build
Install helm
# helm install prometheus prometheus-
community/prometheus
Go to the browser:
take the public ip of the masternode and nodeport
number
reryRHYhWYbtqnuDK5MkKsg3iT28zNBri0lUnt8S