Automation
Automation
Making manual tasks run automatically. Infrastructure, deployment, and test automation. Central to DevOps.
Automation
Making manual tasks run automatically. Infrastructure, deployment, and test automation. Central to DevOps.
Automation is making repetitive tasks that people used to perform manually run automatically through scripts, tools, or systems. In the IT field, automation is applied to almost every area, including infrastructure provisioning, code build/test/deployment, monitoring and alerting, and security checks. The core goals of automation are to reduce human error, increase work speed, ensure consistency, and let engineers focus on creative work.
Infrastructure automation (Infrastructure as Code, IaC) is an approach in which infrastructure such as servers, networks, and storage is defined as code and provisioned automatically. With tools such as Terraform, Pulumi, and AWS CloudFormation, hundreds of servers can be created with identical configurations in just a few minutes. Because infrastructure code is version-controlled, change history tracking, rollback, and code review are possible, and consistency across development/staging/production environments is ensured.
CI/CD (Continuous Integration/Continuous Deployment) is the core of software development automation. When a developer commits code, build, unit tests, integration tests, and code quality checks run automatically (CI), and the verified code is automatically deployed to the staging or production environment (CD). Tools such as GitHub Actions, GitLab CI, Jenkins, and CircleCI are widely used. Test automation is especially important, because it allows you to verify, without human intervention, that a change does not break existing functionality (regression testing).
Operations automation includes system monitoring, log analysis, alerting, and even incident response. For example, when server CPU utilization exceeds 90%, instances can be added automatically (Auto Scaling), or when a security anomaly is detected, the IP can be blocked automatically and a notification sent to the person in charge. Configuration management tools such as Ansible, Chef, and Puppet apply the same settings to thousands of servers at once and detect drift (configuration inconsistency). In MLOps, automating everything from model training, evaluation, and deployment to retraining enables continuous improvement of AI systems.
# .github/workflows/ci-cd.yml
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
NODE_VERSION: '20'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# 1. 코드 품질 검사 (병렬 실행)
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run type check
run: npm run type-check
- name: Run unit tests
run: npm test -- --coverage
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
# 2. 보안 스캔
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
severity: 'CRITICAL,HIGH'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
# 3. Docker 이미지 빌드 및 푸시
build-and-push:
needs: [lint-and-test, security-scan]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 4. 스테이징 환경 배포
deploy-staging:
needs: build-and-push
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- name: Deploy to Kubernetes (Staging)
uses: azure/k8s-deploy@v4
with:
manifests: k8s/staging/
images: ${{ needs.build-and-push.outputs.image-tag }}
namespace: staging
- name: Run smoke tests
run: |
sleep 30 # 배포 안정화 대기
curl -f https://staging.example.com/health || exit 1
# 5. 프로덕션 배포 (수동 승인 필요)
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production # 승인 필요 설정
steps:
- uses: actions/checkout@v4
- name: Deploy to Kubernetes (Production)
uses: azure/k8s-deploy@v5
with:
manifests: k8s/production/
images: ${{ needs.build-and-push.outputs.image-tag }}
namespace: production
strategy: canary
percentage: 20
- name: Monitor canary deployment
run: |
# 카나리 배포 모니터링 (에러율 체크)
./scripts/monitor-canary.sh --threshold 1%
# main.tf - AWS 인프라 자동 프로비저닝
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
# 상태 파일 원격 저장 (팀 협업)
backend "s3" {
bucket = "my-terraform-state"
key = "production/terraform.tfstate"
region = "ap-northeast-2"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
provider "aws" {
region = var.aws_region
default_tags {
tags = {
Environment = var.environment
ManagedBy = "Terraform"
Project = var.project_name
}
}
}
# 변수 정의
variable "environment" {
description = "배포 환경 (staging, production)"
type = string
}
variable "aws_region" {
default = "ap-northeast-2"
}
variable "project_name" {
default = "my-app"
}
# VPC 및 네트워크 (모듈 사용)
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
name = "${var.project_name}-vpc"
cidr = "10.0.0.0/16"
azs = ["${var.aws_region}a", "${var.aws_region}b", "${var.aws_region}c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
single_nat_gateway = var.environment == "staging" ? true : false
enable_dns_hostnames = true
enable_dns_support = true
}
# EKS 클러스터
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"
cluster_name = "${var.project_name}-${var.environment}"
cluster_version = "1.28"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
main = {
min_size = var.environment == "production" ? 3 : 1
max_size = var.environment == "production" ? 10 : 3
desired_size = var.environment == "production" ? 3 : 1
instance_types = ["t3.medium"]
labels = {
Environment = var.environment
}
}
}
# 클러스터 오토스케일링 활성화
cluster_addons = {
coredns = { most_recent = true }
kube-proxy = { most_recent = true }
vpc-cni = { most_recent = true }
}
}
# RDS (PostgreSQL)
module "rds" {
source = "terraform-aws-modules/rds/aws"
version = "~> 6.0"
identifier = "${var.project_name}-${var.environment}"
engine = "postgres"
engine_version = "15"
family = "postgres15"
major_engine_version = "15"
instance_class = var.environment == "production" ? "db.r6g.large" : "db.t3.micro"
allocated_storage = 20
max_allocated_storage = 100
db_name = "myapp"
username = "admin"
port = 5432
multi_az = var.environment == "production"
db_subnet_group_name = module.vpc.database_subnet_group_name
vpc_security_group_ids = [aws_security_group.rds.id]
backup_retention_period = var.environment == "production" ? 7 : 1
deletion_protection = var.environment == "production"
}
# 출력
output "eks_cluster_endpoint" {
value = module.eks.cluster_endpoint
}
output "rds_endpoint" {
value = module.rds.db_instance_endpoint
sensitive = true
}
# playbooks/setup-webserver.yml
---
- name: 웹 서버 구성 자동화
hosts: webservers
become: yes
vars:
app_user: appuser
app_dir: /opt/myapp
nginx_version: "1.24"
tasks:
- name: 시스템 패키지 업데이트
apt:
update_cache: yes
upgrade: safe
when: ansible_os_family == "Debian"
- name: 필수 패키지 설치
apt:
name:
- nginx
- python3-pip
- certbot
- python3-certbot-nginx
- fail2ban
state: present
- name: 애플리케이션 사용자 생성
user:
name: "{{ app_user }}"
shell: /bin/bash
home: "{{ app_dir }}"
create_home: yes
- name: Nginx 설정 파일 배포
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/sites-available/myapp
validate: 'nginx -t -c /etc/nginx/nginx.conf'
notify: Reload Nginx
- name: 사이트 활성화
file:
src: /etc/nginx/sites-available/myapp
dest: /etc/nginx/sites-enabled/myapp
state: link
notify: Reload Nginx
- name: 방화벽 규칙 설정
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "22"
- "80"
- "443"
- name: Fail2ban 설정
template:
src: templates/jail.local.j2
dest: /etc/fail2ban/jail.local
notify: Restart Fail2ban
- name: 로그 로테이션 설정
template:
src: templates/logrotate.conf.j2
dest: /etc/logrotate.d/myapp
handlers:
- name: Reload Nginx
service:
name: nginx
state: reloaded
- name: Restart Fail2ban
service:
name: fail2ban
state: restarted
# inventory/production.yml
---
all:
children:
webservers:
hosts:
web1:
ansible_host: 10.0.1.10
web2:
ansible_host: 10.0.1.11
web3:
ansible_host: 10.0.1.12
vars:
ansible_user: deploy
ansible_python_interpreter: /usr/bin/python3
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free