Skip to content

Instantly share code, notes, and snippets.

@dims
Created September 21, 2025 20:35
Show Gist options
  • Save dims/80e556414989f30b9a500957460a7855 to your computer and use it in GitHub Desktop.
Save dims/80e556414989f30b9a500957460a7855 to your computer and use it in GitHub Desktop.
validate the nginx configuration in k8s.io/apps/k8s-io
❯ pwd
/Users/dsrinivas/go/src/k8s.io/k8s.io/apps/k8s-io
❯ ./validate-nginx.sh
Extracting nginx.conf from ConfigMap...
Extracted nginx.conf to: /var/folders/2x/b5xl9skd2fl0l6tj54fjxh540000gp/T/tmp.tAdbqYOEXU/nginx.conf
Config file size: 380 lines
Validating nginx configuration using Docker...
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2025/09/21 20:33:50 [emerg] 1#1: "server" directive is not allowed here in /etc/nginx/nginx.conf:346
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:346
nginx: configuration file /etc/nginx/nginx.conf test failed
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIGMAP_FILE="${SCRIPT_DIR}/configmap-nginx.yaml"
TEMP_DIR=$(mktemp -d)
NGINX_CONF="${TEMP_DIR}/nginx.conf"
cleanup() {
rm -rf "${TEMP_DIR}"
}
trap cleanup EXIT
echo "Extracting nginx.conf from ConfigMap..."
# Extract the nginx.conf section from the ConfigMap YAML using yq
yq eval '.data."nginx.conf"' "${CONFIGMAP_FILE}" > "${NGINX_CONF}"
echo "Extracted nginx.conf to: ${NGINX_CONF}"
echo "Config file size: $(wc -l < "${NGINX_CONF}") lines"
echo "Validating nginx configuration using Docker..."
# Use the same nginx version as specified in the deployment
NGINX_IMAGE="nginx:1.26-alpine@sha256:5b44a5ab8ab467854f2bf7b835a32f850f32eb414b749fbf7ed506b139cd8d6b"
# Run nginx configuration test
docker run --rm \
-v "${TEMP_DIR}:/etc/nginx:ro" \
"${NGINX_IMAGE}" \
nginx -c /etc/nginx/nginx.conf -t
echo "✅ Nginx configuration validation completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment