DevOps & Scripting Interview Questions Guide
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 {} \;
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
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
bash
3. GitHub Flow
4. GitLab Flow
yaml
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
Terraform Example:
hcl
tags = {
Name = "WebServer"
Environment = "Production"
}
}
6. DevOps Lifecycle
8 Phases of DevOps:
1. Plan - Requirements and project planning
2. Code - Development and version control
Kubernetes Essentials:
Q: What is Kubernetes? Kubernetes is a container orchestration platform that automates
deployment, scaling, and management of containerized applications.
Key Components:
Ansible Overview:
Q: What is Ansible? Ansible is an agentless automation tool for configuration management,
application deployment, and task automation.
yaml
---
- hosts: webservers
tasks:
- name: Install nginx
yum:
name: nginx
state: present
- name: Start nginx service
service:
name: nginx
state: started
On-Premises vs Cloud:
Cloud Advantages:
Global availability
Pay-as-you-use pricing
Managed services
On-Premises Advantages:
No vendor lock-in
Compliance requirements
yaml
Benefits of CI/CD:
1. Faster Time to Market - Automated deployments
2. Reduced Risk - Smaller, frequent releases
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
Problem Solving:
Strategic initiatives
Complex problem-solving
Docker Commands:
bash
Kubernetes Commands:
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!