DevOps & Scripting Interview Questions Guide
1. Linux Scripting
Common Questions:
Q: Write a script to find files older than 30 days and delete them
bash
#!/bin/bash
find /path/to/directory -type f -mtime +30 -delete
# Or with confirmation:
find /path/to/directory -type f -mtime +30 -exec rm -i {} \;
Q: How to check disk usage and send alert if > 80%?
bash
#!/bin/bash
THRESHOLD=80
DISK_USAGE=$(df -h | grep '/dev/sda1' | awk '{print $5}' | sed 's/%//')
if [ $DISK_USAGE -gt $THRESHOLD ]; then
echo "Disk usage is ${DISK_USAGE}%" | mail -s "Disk Alert" [email protected]
fi
Q: Script to monitor a service and restart if down
bash
#!/bin/bash
SERVICE="nginx"
if ! systemctl is-active --quiet $SERVICE; then
systemctl restart $SERVICE
echo "$(date): $SERVICE restarted" >> /var/log/service-monitor.log
fi
Key Linux Commands:
grep , awk , sed , cut , sort , uniq
ps , top , htop , netstat , lsof
systemctl , service , crontab
chmod , chown , umask
2. Git & Version Control
Essential Git Questions:
Q: Explain Git branching strategy
Main/Master: Production-ready code
Develop: Integration branch for features
Feature branches: Individual feature development
Release branches: Prepare releases
Hotfix branches: Emergency fixes
Q: How to revert a commit that's already pushed?
bash
# Create a new commit that undoes changes
git revert <commit-hash>
# Force rewrite history (dangerous for shared repos)
git reset --hard <commit-hash>
git push --force
Q: Difference between git merge and git rebase ?
Merge: Creates a merge commit, preserves branch history
Rebase: Replays commits on top of another branch, linear history
Git Workflow Best Practices:
1. Feature Branch Workflow
2. Gitflow Workflow
3. GitHub Flow
4. GitLab Flow
3. CI/CD Pipeline Tools
Popular CI/CD Tools:
1. Jenkins - Open source, highly customizable
2. GitHub Actions - Integrated with GitHub
3. GitLab CI/CD - Built into GitLab
4. Azure DevOps - Microsoft's solution
5. AWS CodePipeline - AWS native
6. CircleCI - Cloud-based
7. Travis CI - Simple for open source
CI/CD Pipeline Stages:
1. Source - Code commit triggers pipeline
2. Build - Compile and package application
3. Test - Unit, integration, security tests
4. Deploy to Staging - Deploy to test environment
5. Production Deployment - Deploy to live environment
6. Monitor - Track application performance
4. Git Branches & Deployment Control
Branch Protection Rules:
yaml
# GitHub Actions - Deploy only from main
name: Deploy
on:
push:
branches: [ main, release/* ]
jobs:
deploy:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy
run: ./deploy.sh
Branch-based Deployment Strategy:
Main branch → Production
Release branches → Staging/Pre-prod
Feature branches → Development environment
PR-based → Review apps/temporary environments
5. Infrastructure as Code (IaC)
Popular IaC Tools:
1. Terraform - Multi-cloud, declarative
2. AWS CloudFormation - AWS-specific
3. Azure Resource Manager (ARM) - Azure-specific
4. Pulumi - Programming language based
5. Ansible - Configuration management + IaC
Terraform Example:
hcl
resource "aws_instance" "web" {
ami = "ami-0c02fb55956c7d316"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
Environment = "Production"
}
}
6. DevOps Lifecycle
8 Phases of DevOps:
1. Plan - Requirements and project planning
2. Code - Development and version control
3. Build - Compilation and packaging
4. Test - Automated testing
5. Release - Release management
6. Deploy - Deployment automation
7. Operate - Production operations
8. Monitor - Performance monitoring and feedback
7. Containerization & Orchestration
Docker Key Concepts:
Q: What is Docker? Docker is a containerization platform that packages applications with their
dependencies into lightweight, portable containers.
Q: Docker vs Virtual Machines?
Docker: Shares OS kernel, lightweight, faster startup
VMs: Full OS isolation, heavier, more secure isolation
Kubernetes Essentials:
Q: What is Kubernetes? Kubernetes is a container orchestration platform that automates
deployment, scaling, and management of containerized applications.
Key Components:
Pods - Smallest deployable units
Services - Network abstraction
Deployments - Manage replica sets
ConfigMaps/Secrets - Configuration management
Ingress - External access management
Ansible Overview:
Q: What is Ansible? Ansible is an agentless automation tool for configuration management,
application deployment, and task automation.
Ansible Playbook Example:
yaml
---
- hosts: webservers
tasks:
- name: Install nginx
yum:
name: nginx
state: present
- name: Start nginx service
service:
name: nginx
state: started
8. Cloud Platform Comparison
AWS vs Azure vs GCP for DevOps:
AWS DevOps Services:
CI/CD: CodePipeline, CodeBuild, CodeDeploy
Infrastructure: CloudFormation, CDK
Monitoring: CloudWatch, X-Ray
Container: ECS, EKS, Fargate
Azure DevOps Services:
CI/CD: Azure Pipelines, Azure DevOps
Infrastructure: ARM Templates, Bicep
Monitoring: Application Insights, Azure Monitor
Container: AKS, Container Instances
Google Cloud DevOps:
CI/CD: Cloud Build, Cloud Deploy
Infrastructure: Deployment Manager, Cloud Foundation Toolkit
Monitoring: Cloud Operations Suite
Container: GKE, Cloud Run
On-Premises vs Cloud:
Cloud Advantages:
Scalability and elasticity
Reduced infrastructure management
Global availability
Pay-as-you-use pricing
Managed services
On-Premises Advantages:
Complete control over infrastructure
Enhanced security for sensitive data
No vendor lock-in
Compliance requirements
Predictable costs for stable workloads
9. YAML & Configuration Management
YAML Best Practices:
yaml
# Good YAML structure
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Ansible Script Example:
yaml
# Install and configure web server
- name: Web Server Setup
hosts: webservers
become: yes
vars:
packages:
- nginx
- git
tasks:
- name: Install packages
package:
name: "{{ item }}"
state: present
loop: "{{ packages }}"
- name: Start and enable nginx
systemd:
name: nginx
state: started
enabled: yes
10. Why CI/CD Pipeline is Essential
Benefits of CI/CD:
1. Faster Time to Market - Automated deployments
2. Reduced Risk - Smaller, frequent releases
3. Improved Quality - Automated testing
4. Better Collaboration - Shared responsibility
5. Faster Feedback - Quick issue identification
6. Consistency - Standardized deployment process
11. Git Actions & Secrets
GitHub Actions Workflow:
yaml
name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Tests
run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- name: Deploy to Production
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
echo "Deploying with secure credentials"
./deploy.sh
Managing Secrets:
Repository Secrets - Specific to one repo
Environment Secrets - Environment-specific
Organization Secrets - Shared across repos
Encrypted at rest and in transit
12. AI vs DevOps Engineer
Why DevOps Engineers are Still Needed:
Strategic Planning:
AI can't understand business context
Complex architectural decisions require human judgment
Cross-team collaboration and communication
Problem Solving:
Debugging complex, interconnected systems
Incident response and root cause analysis
Custom solutions for unique business requirements
Security & Compliance:
Security strategy and implementation
Compliance with industry regulations
Risk assessment and mitigation
Innovation & Optimization:
Performance tuning and optimization
Cost optimization strategies
Technology evaluation and adoption
AI as a Tool, Not Replacement:
AI enhances DevOps capabilities
Automates repetitive tasks
Provides insights from data analysis
DevOps engineers orchestrate AI tools
The Future Role:
DevOps engineers will focus more on:
Strategic initiatives
Complex problem-solving
AI/ML operations (MLOps)
Platform engineering
Developer experience optimization
Quick Reference Commands
Essential Git Commands:
bash
git clone <repo-url>
git checkout -b feature/new-feature
git add .
git commit -m "Add new feature"
git push origin feature/new-feature
git merge main
git rebase main
git log --oneline --graph
Docker Commands:
bash
docker build -t myapp:latest .
docker run -d -p 8080:80 myapp:latest
docker ps
docker logs <container-id>
docker exec -it <container-id> /bin/bash
docker-compose up -d
Kubernetes Commands:
bash
kubectl get pods
kubectl describe pod <pod-name>
kubectl apply -f deployment.yaml
kubectl scale deployment myapp --replicas=5
kubectl logs -f <pod-name>
kubectl exec -it <pod-name> -- /bin/bash
This comprehensive guide covers the most important DevOps concepts and practical examples
you're likely to encounter in interviews. Practice these commands and concepts hands-on for better
understanding!