0% found this document useful (0 votes)
3 views3 pages

DevOps Interview Scripts

The document contains various DevOps basic interview scripts covering shell scripting for service monitoring, Terraform for EC2 instance creation, Ansible for Nginx installation, Jenkins pipeline for application deployment, a Dockerfile for a Node application, Kubernetes deployment and service configuration, and a Python script for API health checks. Each script is designed to demonstrate fundamental DevOps concepts and practices. These examples serve as practical tools for candidates preparing for DevOps interviews.

Uploaded by

Adarsh R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

DevOps Interview Scripts

The document contains various DevOps basic interview scripts covering shell scripting for service monitoring, Terraform for EC2 instance creation, Ansible for Nginx installation, Jenkins pipeline for application deployment, a Dockerfile for a Node application, Kubernetes deployment and service configuration, and a Python script for API health checks. Each script is designed to demonstrate fundamental DevOps concepts and practices. These examples serve as practical tools for candidates preparing for DevOps interviews.

Uploaded by

Adarsh R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DevOps Basic Interview Scripts

1. Shell Script - Service Monitoring

#!/bin/bash
SERVICE="nginx"

if systemctl is-active --quiet $SERVICE


then
echo "$SERVICE is running"
else
echo "$SERVICE is down. Restarting..."
systemctl restart $SERVICE
fi

2. Terraform - EC2 Instance

provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "demo" {


ami = "ami-0c55b159cbfafe1f0"
instance_type = "[Link]"

tags = {
Name = "Interview-Instance"
}
}

3. Ansible - Install Nginx

---
- name: Install Nginx
hosts: all
become: yes

tasks:
- name: Install nginx
apt:
name: nginx
state: present

4. Jenkins Declarative Pipeline


pipeline {
agent any

stages {
stage('Build') {
steps {
echo 'Building Application...'
}
}

stage('Test') {
steps {
echo 'Running Tests...'
}
}

stage('Deploy') {
steps {
echo 'Deploying Application...'
}
}
}
}

5. Dockerfile - Node App

FROM node:18

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

6. Kubernetes Deployment + Service

apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
replicas: 2
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers:
- name: demo-container
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
spec:
type: NodePort
selector:
app: demo
ports:
- port: 80
targetPort: 80

7. Python - API Health Check

import requests

url = "[Link]
response = [Link](url)

if response.status_code == 200:
print("Application is Healthy")
else:
print("Application is Down")

You might also like