0% found this document useful (0 votes)
7 views37 pages

Interview Question

Uploaded by

komobol463
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)
7 views37 pages

Interview Question

Uploaded by

komobol463
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

Junior/Intern Level DevOps Interview Questions & Answers

TERRAFORM (Beginner Level)

Q1: What is Terraform and why do we use it?

Answer: Terraform is an Infrastructure as Code (IaC) tool that allows you to define and manage cloud
infrastructure using configuration files instead of manually clicking through cloud provider consoles.

Why use it:

Automation: Deploy infrastructure automatically without manual steps


Consistency: Same configuration deployed multiple times gives identical results
Version control: Store infrastructure in Git like code
Easy replication: Quickly create dev/staging/prod environments
Documentation: Code itself documents what infrastructure exists

Example: Instead of manually creating an EC2 instance in AWS console, you write:

hcl

resource "aws_instance" "web" {


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

Q2: What's the difference between terraform plan and terraform apply ?

Answer:

terraform plan : Shows you what WILL happen but doesn't actually make changes. It's like a preview of
your changes. Always run this first to verify changes.
terraform apply : Actually executes the changes and creates/updates infrastructure.

Example workflow:

bash
terraform plan # Review what will be created
terraform apply # Create the resources

Q3: What is a Terraform state file and why is it important?

Answer: The state file ([Link]) is a JSON file that tracks all resources Terraform has created. It's a
record of your actual infrastructure.

Why important:

Terraform reads it to know what resources already exist


Prevents recreating resources that already exist
Tracks resource IDs and properties
Used for identifying what changed between deployments

Warning: Never commit state files to Git - they contain sensitive data like passwords and private keys. Store
them in S3, Terraform Cloud, or other secure backends.

Q4: How would you create multiple similar resources (like 3 EC2 instances)?

Answer: Use the count parameter to create multiple resources:

hcl

resource "aws_instance" "web" {


count =3
ami = "ami-0c55b159cbfafe1f0"
instance_type = "[Link]"
tags = {
Name = "web-server-${[Link]}" # Creates web-server-0, web-server-1, web-server-2
}
}

Reference them later:

hcl

aws_instance.web[0].id # First instance ID


aws_instance.web[1].id # Second instance ID
Q5: What are Terraform modules and when would you use them?

Answer: Modules are reusable blocks of Terraform code. Think of them like functions - you write code once
and use it multiple times.

Example structure:

modules/
├── vpc/
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
└── ec2/
├── [Link]
├── [Link]
└── [Link]

Using a module:

hcl

module "prod_vpc" {
source = "./modules/vpc"
cidr = "[Link]/16"
name = "prod-vpc"
}

module "web_servers" {
source = "./modules/ec2"
vpc_id = module.prod_vpc.vpc_id
count = 3
}

Benefits: Reusable, organized, easier to maintain.

ANSIBLE (Beginner Level)

Q6: What is Ansible and what problems does it solve?

Answer: Ansible is a configuration management tool that automates tasks on multiple servers. Instead of SSH-
ing into each server manually, you write a playbook that runs the same commands everywhere.

Problems it solves:

Manual repetitive tasks (installing packages, updating configs)


Inconsistent server setups
Time-consuming deployments
Difficulty updating 100 servers at once

Example: Install and start Apache on 10 servers:

yaml

---
- hosts: webservers
tasks:
- name: Install Apache
apt:
name: apache2
state: present

- name: Start Apache service


service:
name: apache2
state: started

One command runs this on all servers.

Q7: Explain the inventory file and what it does.

Answer: The inventory file lists all servers that Ansible can control. It groups them logically.

Example inventory file:

ini
[webservers]
[Link]
[Link]
[Link]

[databases]
[Link]
[Link]

[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=/home/user/.ssh/id_rsa

Then you can run tasks on specific groups:

bash

ansible-playbook [Link] -i inventory -l webservers # Run only on webservers

Q8: What is idempotency and why is it important in Ansible?

Answer: Idempotency means running the same command multiple times produces the same result - it doesn't
keep changing things.

Example:

yaml

- name: Install nginx


apt:
name: nginx
state: present # "present" means "ensure it's installed"

Run this 1 time: Installs nginx


Run this 5 times: Still just nginx, not installed 5 times

Why important: You can safely run playbooks multiple times without breaking systems. If installation fails,
you can retry without issues.
Q9: What's the difference between handlers and tasks in Ansible?

Answer:

Tasks: Run every time playbook runs


Handlers: Only run when notified by another task

Example:

yaml

tasks:
- name: Update Apache config
copy:
src: [Link]
dest: /etc/apache2/[Link]
notify: Restart Apache # Tells handler to run

handlers:
- name: Restart Apache
service:
name: apache2
state: restarted # Only runs if config was updated

This prevents unnecessary restarts - only restarts when config changes.

Q10: How would you deploy a new application version to 20 production servers?

Answer: Create a playbook that:

1. Stops the application


2. Downloads new version
3. Starts the application
4. Verifies it's running

yaml
---
- hosts: webservers
serial: 5 # Update 5 servers at a time (rolling update)

tasks:
- name: Stop application
service:
name: myapp
state: stopped

- name: Download new version


shell: |
cd /opt/myapp
git fetch origin
git checkout v2.0.0

- name: Install dependencies


shell: |
cd /opt/myapp
npm install

- name: Start application


service:
name: myapp
state: started

- name: Check if application is responding


uri:
url: "[Link]
status_code: 200
retries: 3
delay: 2

The serial: 5 ensures only 5 servers update at a time, keeping others available.

AWS (Beginner Level)

Q11: What is EC2 and what would you use it for?

Answer: EC2 (Elastic Compute Cloud) is AWS's virtual machine service. You can rent computers in the cloud
instead of buying physical servers.
Use cases:

Running web applications


Running databases
Running batch jobs
Running any software that needs a computer

Basic process:

1. Choose instance type (size of computer: [Link], [Link], etc.)


2. Choose operating system (AMI - Amazon Machine Image)
3. Configure security (security groups - like firewalls)
4. Launch and connect via SSH
5. Install your application

You pay per hour, so you can create/delete as needed.

Q12: What are Security Groups and why are they important?

Answer: Security Groups are firewalls that control which traffic can reach your instances. They define which
ports are open and from where.

Example:

Inbound rules:
- Port 22 (SSH) from [Link]/0 (anywhere)
- Port 80 (HTTP) from [Link]/0 (anywhere)
- Port 443 (HTTPS) from [Link]/0 (anywhere)
- Port 3306 (MySQL) from security group "web-servers" only

Outbound rules:
- All traffic allowed (default)

This means:

Anyone can SSH to the server


Anyone can visit web pages (HTTP/HTTPS)
Only web servers in the "web-servers" security group can connect to MySQL
Server can make outbound connections to anywhere
Q13: Explain the difference between EBS and S3.

Answer:

EBS (Elastic Block Storage): Virtual hard drive for EC2 instances. Only one instance can use it. Data
persists if instance stops.
Like: A hard drive inside a computer
Use for: Databases, applications, OS files

S3 (Simple Storage Service): Cloud storage for files. Multiple services can access it. Stores objects
(files).
Like: Dropbox or Google Drive for the cloud
Use for: Backups, images, documents, logs, static websites

EC2 instance with EBS → Running application


S3 bucket → Storing application backups and user uploads

Q14: What is an IAM role and why would you use it?

Answer: IAM role is a set of permissions that controls what an EC2 instance (or other AWS service) can do.
Instead of storing passwords/keys on the instance, attach a role.

Example IAM role for EC2:

json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}

This role allows the instance to:

Read files from S3 bucket "my-bucket"


List files in the bucket

But it CANNOT:

Delete files
Access other S3 buckets
Modify EC2 instances

Benefits:

No passwords/keys on the instance (more secure)


Easy to revoke permissions
Automatic credential rotation

Q15: What is an Auto Scaling Group and why would you use one?

Answer: An Auto Scaling Group automatically creates/deletes EC2 instances based on traffic demand.

Example:
Minimum: 2 instances (always running)
Maximum: 10 instances (won't go higher)
Desired: 3 instances (current target)

Scaling policy: If CPU > 80% for 2 minutes, add 1 instance


If CPU < 20% for 5 minutes, remove 1 instance

Scenario:

3 PM: Normal traffic, 3 instances running


4 PM: Traffic spikes, CPU goes to 90%, Auto Scaling Group adds instances → 5 running
7 PM: Traffic drops, instances reduce back to 3
Cost savings: Only pay for what you use

DOCKER (Beginner Level)

Q16: What is Docker and what problem does it solve?

Answer: Docker is containerization - it packages your application and all its dependencies into a single unit
called a container.

Problem it solves:

"Works on my machine but not on the server"


Application needs Java 8, but server has Java 11
Different libraries on development vs production
Difficult to deploy applications consistently

Example: Without Docker: Application needs [Link] 16, Python 3.9, Redis - lots of setup With Docker: One
Docker image contains everything - just run it anywhere

Q17: What's the difference between an image and a container?

Answer:

Image: Blueprint/recipe (like a class in programming)


Container: Running instance of an image (like an object)
Analogy:

Image = Cookie cutter


Container = Baked cookie

One image can create many containers:

bash

docker run my-app # Creates container 1


docker run my-app # Creates container 2
docker run my-app # Creates container 3

All three containers run from the same image but are separate instances.

Q18: What is a Dockerfile and what does each command do?

Answer: Dockerfile is a recipe to build a Docker image. Each line creates a layer.

Example Dockerfile:

dockerfile

FROM ubuntu:20.04
# Start from Ubuntu Linux base image

RUN apt-get update && apt-get install -y nodejs npm


# Install [Link] and npm (like running commands)

WORKDIR /app
# Set working directory to /app

COPY . /app
# Copy application code from computer into container

EXPOSE 8080
# Document that application listens on port 8080

CMD ["node", "[Link]"]


# Default command to run when container starts

Build and run:


bash

docker build -t my-app:1.0 . # Build image


docker run -p 8080:8080 my-app:1.0 # Run container, map port 8080

Q19: How would you persist data in Docker containers?

Answer: By default, container data is deleted when container stops. Use volumes to persist data.

Example with MySQL:

bash

# Without volume - data is lost


docker run mysql:latest

# With volume - data persists


docker run -v my-db-volume:/var/lib/mysql mysql:latest

The -v flag creates a volume that persists even if container is deleted.

Docker Compose example:

yaml

version: '3'
services:
database:
image: mysql:latest
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret

volumes:
db-data: # Named volume for persistence

Q20: How would you run multiple containers together (web app + database)?

Answer: Use Docker Compose to define and run multiple containers.


[Link]:

yaml

version: '3'
services:
web:
image: my-app:1.0
ports:
- "8080:8080"
environment:
DATABASE_URL: postgresql://db:5432/mydb
depends_on:
- db

db:
image: postgres:13
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb

volumes:
db-data:

Usage:

bash

docker-compose up # Start all containers


docker-compose down # Stop all containers
docker-compose logs web # View web app logs
docker-compose exec db psql # Run command in db container

The depends_on: db ensures database starts before web app.

GITHUB ACTIONS (Beginner Level)

Q21: What are GitHub Actions and what would you use them for?

Answer: GitHub Actions are automated workflows that run when something happens in your repository (like
pushing code or creating a pull request).

Common uses:

Run tests automatically when code is pushed


Build Docker images automatically
Deploy application automatically
Check code quality

Workflow: Code push → Tests run → If pass, deploy → If fail, notify developer

Q22: What is a GitHub Actions workflow file and where does it go?

Answer: Workflow files are YAML files stored in .github/workflows/ directory in your repository.

Example structure:

my-repository/
├── .github/
│ └── workflows/
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
├── src/
├── [Link]
└── [Link]

Each file defines a different automation workflow.

Q23: Walk me through a simple workflow that runs tests on every push.

Answer:

yaml
# .github/workflows/[Link]
name: Run Tests

on:
push:
branches: [main, develop]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup [Link]


uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies


run: npm install

- name: Run linter


run: npm run lint

- name: Run tests


run: npm test

- name: Build application


run: npm run build

What happens:

1. Code pushed to main branch


2. GitHub Actions starts
3. Checks out your code
4. Sets up [Link] 16
5. Installs npm packages
6. Runs linting
7. Runs tests
8. Builds application
9. If any step fails, workflow stops and notifies you

Q24: How do you pass secret values to a GitHub Actions workflow?

Answer: Use GitHub Secrets to store sensitive values like API keys and passwords.

Steps:

1. Go to repository Settings → Secrets


2. Click "New repository secret"
3. Add secret: AWS_ACCESS_KEY_ID with value

4. Use in workflow:

yaml

- name: Deploy to AWS


run: |
aws s3 cp build/ s3://my-bucket/
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

The ${{ secrets.SECRET_NAME }} accesses the secret value. It's hidden in logs and not exposed.

Q25: How would you deploy an application automatically when code is merged to main branch?

Answer:

yaml
# .github/workflows/[Link]
name: Deploy to Production

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build Docker image


run: docker build -t my-app:${{ [Link] }} .

- name: Push to Docker Registry


run: |
docker tag my-app:${{ [Link] }} my-app:latest
docker push my-app:latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

- name: Deploy to production


run: |
aws ecs update-service \
--cluster production \
--service my-app \
--force-new-deployment
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Notify Slack


if: success()
run: |
curl -X POST ${{ secrets.SLACK_WEBHOOK }} \
-d '{"text":"Deployment successful!"}'

Workflow:
1. Code merged to main
2. Docker image built with new code
3. Image pushed to registry
4. Production deployment updated with new image
5. Team notified via Slack

PROMETHEUS (Beginner Level)

Q26: What is Prometheus and what does it do?

Answer: Prometheus is a monitoring system that collects metrics (measurements) from your applications and
infrastructure.

What it monitors:

CPU usage
Memory usage
Disk space
Application response times
Error rates
Database connections
Anything you program it to track

How it works:

1. Applications expose metrics on /metrics endpoint


2. Prometheus scrapes (reads) these metrics every 15 seconds
3. Stores metrics in database
4. You query the data to create alerts and dashboards

Q27: What's a metric and what are the main types in Prometheus?

Answer: A metric is a measurement of something. Main types:

1. Counter: Always goes up (like a car odometer)


http_requests_total: 1000
(After 100 more requests)
http_requests_total: 1100

Use for: Number of requests, errors, transactions

2. Gauge: Can go up or down (like a thermometer)

cpu_temperature: 65
(Later)
cpu_temperature: 72

Use for: CPU usage, memory usage, connections

3. Histogram: Measures distribution (like age groups)

http_request_duration_seconds_bucket{le="0.1"}: 500
http_request_duration_seconds_bucket{le="0.5"}: 800
http_request_duration_seconds_bucket{le="1.0"}: 950

Use for: Request latencies, response times

Q28: How would you scrape metrics from an application?

Answer: Configure Prometheus to scrape your application's /metrics endpoint.

[Link]:

yaml
global:
scrape_interval: 15s # Scrape every 15 seconds

scrape_configs:
- job_name: 'web-application'
static_configs:
- targets: ['localhost:8080']

- job_name: 'database'
static_configs:
- targets: ['db-server:9090']

- job_name: 'nodejs-app'
static_configs:
- targets: ['[Link]']

Prometheus will:

1. Visit [Link] every 15 seconds


2. Parse the metrics
3. Store them in its database
4. Make them available for queries

Q29: What's an alert rule in Prometheus?

Answer: An alert rule defines conditions that trigger alerts when something goes wrong.

Example alert rule:

yaml
groups:
- name: application_alerts
rules:
- alert: HighCPUUsage
expr: cpu_usage > 80
for: 5m
annotations:
summary: "CPU usage is above 80%"
description: "Server {{ $[Link] }} has CPU > 80% for 5 minutes"

- alert: HighErrorRate
expr: (error_count / total_requests) > 0.05
for: 2m
annotations:
summary: "Error rate above 5%"

What this does:

Checks if CPU > 80%


If true for 5 minutes, fires alert (not just once, must be sustained)
Sends alert to AlertManager which sends emails/Slack/PagerDuty

Q30: How would you write a simple PromQL query?

Answer: PromQL is the query language to get data from Prometheus.

Simple examples:
# Get current CPU usage
node_cpu_usage_percent

# Get memory usage as percentage


(node_memory_used_bytes / node_memory_total_bytes) * 100

# Get 5-minute average CPU


avg_over_time(node_cpu_usage_percent[5m])

# Get requests per second (rate of change)


rate(http_requests_total[1m])

# Filter by labels
http_requests_total{job="web-app", status="200"}

# Sum across all instances


sum(http_requests_total)

# Count how many servers have high CPU


count(node_cpu_usage_percent > 80)

GRAFANA (Beginner Level)

Q31: What is Grafana and what does it do?

Answer: Grafana is a visualization tool that displays metrics in dashboards and graphs.

What it does:

Connects to Prometheus and gets data


Creates beautiful charts and graphs
Alerts when something goes wrong
Provides single dashboard to monitor everything
Makes data easier to understand (visual instead of numbers)

Example dashboard: Shows CPU, memory, disk, network, application latency all on one page with graphs.
Q32: What's the difference between a dashboard and a panel in Grafana?

Answer:

Dashboard: Entire page with multiple visualizations (like a car dashboard)


Panel: Single chart/graph (like a speedometer on a car dashboard)

Dashboard might have 10 panels:

CPU usage graph


Memory usage graph
Request latency graph
Error rate graph
Disk usage gauge
etc.

Q33: How would you create a simple graph showing request latency over time?

Answer:

1. Create new dashboard


2. Add a panel
3. Select data source (Prometheus)
4. Enter PromQL query:

histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))

This shows 95th percentile (P95) latency


5. Configure visualization as line graph
6. Add title: "Request Latency P95"
7. Save dashboard

Q34: What's an alert in Grafana and how would you set one up?

Answer: Alert notifies you when something crosses a threshold.

Steps to create alert:


1. Edit panel
2. Click "Alert" tab
3. Set condition: "When value is above 80"
4. Set "for" duration: "5 minutes"
5. Add notification channel (Slack, Email, PagerDuty)
6. Save

Example alert:

Alert name: "High Memory Usage"


Condition: When memory > 85% for 5 minutes
Notify: Send to Slack #alerts channel
Message: "Server {{ $[Link] }} has memory above 85%"

When memory exceeds 85% for 5 minutes → Slack message sent → On-call engineer sees it

Q35: What would you do if you need to show application metrics that Prometheus doesn't have?

Answer: Instrument your application to emit metrics.

Example in [Link]:

javascript
const prometheus = require('prom-client');

// Create a counter
const requestCounter = new [Link]({
name: 'app_requests_total',
help: 'Total application requests',
labelNames: ['method', 'status']
} );

// Increment counter
[Link]({ method: 'GET', status: 200 });

// Expose metrics endpoint


[Link]('/metrics', (req, res) => {
[Link]('Content-Type', [Link]);
[Link]([Link]());
} );

Then Prometheus scrapes your /metrics endpoint and Grafana displays the data.

NGINX (Beginner Level)

Q36: What is NGINX and what does it do?

Answer: NGINX is a web server and reverse proxy. It's fast and efficient.

Main uses:

1. Web server: Serves web pages (like Apache)


2. Reverse proxy: Routes requests to backend servers
3. Load balancer: Distributes traffic to multiple servers
4. Cache: Stores responses to reduce load on backends

Q37: What's the difference between a web server and a reverse proxy?

Answer:

Web server: Directly serves files (HTML, CSS, images). Client connects to it.
Reverse proxy: Sits in front of backend servers. Routes requests. Client connects to proxy, proxy
connects to backend.

Web server:

Client → NGINX → Serves static files

Reverse proxy:

Client → NGINX → Routes to App Server 1, 2, or 3

Reverse proxy benefits:

Load balancing (distribute traffic)


Hide backend servers (security)
Cache responses (performance)
Handle SSL/TLS encryption

Q38: How would you configure NGINX to route traffic to multiple backend servers?

Answer: Define an upstream block with multiple servers.

nginx
# Define backend servers
upstream app_servers {
server [Link];
server [Link];
server [Link];
}

server {
listen 80;
server_name [Link];

location / {
proxy_pass [Link]
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}

How it works:

Request 1 → Goes to app1


Request 2 → Goes to app2
Request 3 → Goes to app3
Request 4 → Goes back to app1
(Round-robin load balancing)

If app1 goes down, NGINX automatically routes to app2 and app3.

Q39: How would you set up HTTPS/SSL in NGINX?

Answer:

nginx
server {
listen 443 ssl;
server_name [Link];

ssl_certificate /etc/ssl/certs/[Link];
ssl_certificate_key /etc/ssl/private/[Link];
ssl_protocols TLSv1.2 TLSv1.3;

location / {
proxy_pass [Link]
}
}

# Redirect HTTP to HTTPS


server {
listen 80;
server_name [Link];
return 301 [Link]
}

What this does:

Listen on port 443 (HTTPS)


Use SSL certificate and private key
Force modern TLS versions (secure)
Redirect HTTP to HTTPS

Q40: How would you implement basic caching in NGINX?

Answer: Configure proxy cache to store responses.

nginx
# Define cache storage
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m;

server {
listen 80;

location / {
proxy_cache my_cache;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 10m; # Cache 200 responses for 10 minutes
proxy_cache_valid 404 1m; # Cache 404s for 1 minute

add_header X-Cache-Status $upstream_cache_status; # Show if hit/miss

proxy_pass [Link]
}
}

How it works:

First request → Fetches from backend, stores in cache


Second request (within 10 min) → Serves from cache (much faster, no backend call)
After 10 minutes → Cache expires, fetches fresh data

Result: Faster responses, less load on backend.

Scenario Questions (Beginner Level)

Scenario 1: Website is loading slowly

Situation: Your team's website is loading slowly. You have 2 backend servers and NGINX is routing traffic.
Where would you check?

Solution:

1. Check backend server CPU/memory (maybe they're overloaded)


2. Check NGINX logs to see response times
3. Check if database is slow
4. Maybe need to add more backend servers
5. Maybe need to enable caching in NGINX
Scenario 2: Can't deploy new application version

Situation: You tried to deploy an updated Docker image to production but it's not taking effect.

Solution:

1. Check if Docker image was actually pushed (docker push succeeded?)


2. Check if Kubernetes/Docker is using the new image
3. Force pull latest image
4. Restart containers
5. Verify new version is running

Scenario 3: Application broke after Terraform change

Situation: You ran terraform apply and now application is down.

Solution:

1. Run terraform plan to see what changed


2. Check what resources were modified/deleted
3. If critical resource was deleted, restore it
4. Use terraform state to investigate
5. Run terraform apply again to fix
6. Next time, always run terraform plan first and review carefully

Scenario 4: Ansible playbook failed on 10 servers

Situation: Deployed with Ansible but failed midway on 10 of 20 servers.

Solution:

1. SSH to failed servers and check error logs


2. Fix the issue (wrong config, missing dependency, etc.)
3. Run playbook again with --start-at-task "failed task name" to retry from that point
4. Update playbook to prevent error next time
5. Add better error handling and validation

Scenario 5: Prometheus out of disk space

Situation: Prometheus stops working because disk is full. Metrics aren't being stored.

Solution:

1. Check disk usage: df -h


2. Prometheus stores data in /var/lib/prometheus/ - check size
3. Delete old metrics or increase disk size
4. Adjust retention period in [Link] (e.g., keep only 15 days of data)
5. Restart Prometheus
6. Set up disk space alerts so this doesn't happen again

Scenario 6: Grafana dashboard shows no data

Situation: You created a Grafana dashboard with PromQL query but it shows empty graph.

Solution:

1. Check if Prometheus is connected (Data Sources → Prometheus)


2. Test PromQL query in Prometheus UI directly
3. If query fails, metric might not exist or naming is wrong
4. Check Prometheus targets - are they being scraped?
5. Application might not be emitting that metric
6. Look at actual metrics available: /metrics endpoint

Scenario 7: GitHub Actions workflow won't run

Situation: You created workflow in .github/workflows/[Link] but it's not running automatically.

Solution:

1. Check if file is in correct location: .github/workflows/[Link]


2. Check YAML syntax (spaces, indentation)
3. Check on: trigger - did you define when it should run?
4. Commit and push file to repository
5. Go to Actions tab to see if workflow appears
6. If still not working, check for syntax errors in workflow file

Scenario 8: Docker container exits immediately

Situation: You run docker run my-app but container stops after a few seconds.

Solution:

1. Check logs: docker logs container_id


2. Application might have crashed or finished
3. Check Dockerfile CMD - does it start the right service?
4. Run container with bash to debug: docker run -it my-app bash
5. Manually run the command from Dockerfile
6. Fix the issue and rebuild image

Scenario 9: AWS security group blocking traffic

Situation: Your EC2 instance is running but you can't connect to application on port 8080.

Solution:

1. Check security group inbound rules


2. Add rule: Port 8080, Source [Link]/0 (or your IP)
3. Or from Terraform:

hcl
resource "aws_security_group_rule" "allow_app" {
type = "ingress"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["[Link]/0"]
security_group_id = aws_security_group.[Link]
}

4. Test connection again

Scenario 10: High CPU usage alert triggered

Situation: Grafana alert shows CPU > 80% on production server.

Solution:

1. SSH to server and check what process is using CPU: top


2. Find process name and ID
3. Check why it's using high CPU (maybe memory is full and swapping?)
4. Check application logs for errors
5. Restart service if it's stuck: systemctl restart myapp
6. Monitor to see if CPU goes down
7. If persistent, add more servers or optimize code
8. Add dashboard to monitor better going forward

Quick Reference Comparison Questions

Q41: When would you use Terraform vs Ansible?

Answer:

Terraform: Create and manage infrastructure (EC2, S3, VPC, RDS)


Ansible: Configure and manage servers (install packages, update configs, deploy apps)

Combined workflow:
1. Terraform creates infrastructure (10 EC2 instances)
2. Ansible configures those instances (install Docker, start services)

Q42: When would you use Docker vs Kubernetes?

Answer:

Docker: Package single application with dependencies


Kubernetes: Manage many Docker containers across many servers

Progression:

Starting: Just Docker, manually run containers


Growing: Docker + Docker Compose (multiple containers)
Large scale: Kubernetes (manage containers across cluster)

Q43: GitHub Actions vs Prometheus vs Grafana - what's each for?

Answer:

GitHub Actions: Automate tests/builds/deploys when code changes


Prometheus: Collect metrics (CPU, memory, requests, etc.)
Grafana: Visualize those metrics and create alerts

Timeline:

Push code → GitHub Actions runs tests → Builds app


App running → Prometheus collects metrics
Metrics in Prometheus → Grafana displays in dashboards

Q44: EC2 vs RDS vs S3 - when to use each?

Answer:

EC2: Virtual computer to run applications


RDS: Managed database (MySQL, PostgreSQL)
S3: File storage (backups, images, documents)

E-commerce example:

EC2: Web server running your store


RDS: Database storing products, orders, users
S3: Store product images, customer uploads

Q45: NGINX upstream vs proxy_pass - difference?

Answer:

upstream: Define pool of backend servers


proxy_pass: Route requests to that upstream

nginx

upstream backends { # Define pool


server app1:8080;
server app2:8080;
}

location / {
proxy_pass [Link] # Use the pool
}

Tips for Intern Interview Success

1. Ask clarifying questions: If you don't understand, ask!


2. Think out loud: Explain your reasoning as you answer
3. Admit when you don't know: "I haven't used that yet, but I'd approach it by..."
4. Draw diagrams: Visuals help explain concepts
5. Give examples: Concrete examples better than abstract explanations
6. Relate to what you know: Connect to familiar technologies
7. Show enthusiasm: You're learning! That's good!
8. Practice hands-on: Theory is important but building things is better
9. Read error messages: They usually tell you what's wrong
10. Google is your friend: Finding solutions is a skill too!

You might also like