Kubernetes 네임스페이스에서 실행 중인 파드가 사용하는 컨테이너 이미지 스캔

발행: (2026년 2월 10일 오후 03:17 GMT+9)
1 분 소요
원문: Dev.to

Source: Dev.to

스크립트

#!/bin/bash

namespace="kubernetes-dashboard"

# Create a directory for the scan results
mkdir -p "$namespace"

# Get a list of all the images used by Pods in the Namespace
images=($(kubectl get pods -n "$namespace" -o jsonpath='{.items[*].spec.containers[*].image}' | sort | uniq))

# Loop through the images and scan each one
for image in "${images[@]}"; do
    echo "Scanning image: $image"
    # Scan the image with --scanners vuln to skip scanning for secrets (faster)
    trivy image --severity HIGH,CRITICAL "$image" \
        --scanners vuln --quiet --format json \
        --output "$namespace/$(basename "$image").json"
done

사용법

bash scan_images.sh

스크립트는 kubernetes-dashboard 네임스페이스의 모든 이미지를 스캔하고 Trivy 스캔 결과를 네임스페이스 이름으로 된 디렉터리에 JSON 파일로 저장합니다. namespace 변수를 조정하거나 제거하여 전체 클러스터의 이미지를 스캔할 수 있습니다.

0 조회
Back to Blog

관련 글

더 보기 »