0% found this document useful (0 votes)
16 views12 pages

Capstone Project2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

wget -O- https://apt.releases.hashicorp.

com/gpg | sudo gpg --dearmor -o


/usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg]


https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee
/etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install terraform –y

main.tf

provider "aws" {

region = "us-east-1"

resource "aws_instance" "K8-M" {

ami = "ami-06aa3f7caf3a30282" #Ubuntu 20.04 LTS

instance_type = "t2.medium"

key_name = "daro.io"

subnet_id = "subnet-05419866677eb6366"

tags = {

Name = "Kmaster"

}
resource "aws_instance" "K8-S1" {

ami = "ami-06aa3f7caf3a30282"

instance_type = "t2.micro"

key_name = "daro.io"

subnet_id = "subnet-05419866677eb6366"

tags = {

Name = "Kslave1"

resource "aws_instance" "K8-S2" {

ami = "ami-06aa3f7caf3a30282"

instance_type = "t2.micro"

key_name = "daro.io"

subnet_id = "subnet-05419866677eb6366"

tags = {

Name = "Kslave2"

}
sudo apt update

sudo apt install software-properties-common

sudo add-apt-repository --yes --update ppa:ansible/ansible

sudo apt install ansible –y


inventory.ini

[all:vars]

ansible_user=ubuntu

[kmaster]

Kmaster ansible_host=10.0.1.52

[kslave]

Kslave1 ansible_host=10.0.1.67

Kslave2 ansible_host=10.0.1.119

eval $(ssh-agent -s)

sudo chmod 600 daro.io.pem

ssh-add daro.io.pem

ssh-add –l
ansible-playbook -i inventory.ini playbook.yaml --check

ansible-playbook -i inventory.ini playbook.yaml

git clone https://github.com/sandeeprawat2004/website.git


Dockerfile

FROM ubuntu

RUN apt update

RUN apt-get install apache2 -y

ADD . /var/www/html

ENTRYPOINT apachectl -D FOREGROUND

git status

git add .

git commit -m “some title”

git branch
pipeline {
agent none
environment {
DOCKERHUB_CREDENTIALS = credentials('b0315ace-8823-43b0-9298-60de98187382')
}

stages {
stage('Hello') {
agent {
label 'KMaster'
}
steps {
echo 'Hello World'
}
}
stage('git') {
agent {
label 'KMaster'
}
steps {
git 'https://github.com/sandeeprawatcloud/website.git'
}
}
stage('docker') {
agent {
label 'KMaster'
}
steps {
echo "test"
sh 'sudo docker build /home/ubuntu/jenkins/workspace/pipeline -t docker6767/image'
sh 'sudo echo $DOCKERHUB_CREDENTIALS_PSW | sudo docker login -u $DOCKERHUB_CREDENTIALS_USR
--password-stdin'
sh "sudo docker tag docker6767/image:latest hectorproko/from_jenkins:${env.BUILD_NUMBER}"
sh "sudo docker push hectorproko/from_jenkins:${env.BUILD_NUMBER}"

}
}
stage('Kubernetes') {
agent {
label 'KMaster'
}
steps {
echo "test"
sh 'kubectl create -f deploy.yml'
sh 'kubectl create -f svc.yml'
}
}
}
}

You might also like