apiVersion: apps/v1
kind: Deployment
metadata:
  name: rainbow-deployment
  labels:
    app: rainbow
spec:
  replicas: 3
  selector:
    matchLabels:
      app: rainbow
  template:
    metadata:
      labels:
        app: rainbow
    spec:
      containers:
      - name: rainbow
        image: nginx
        env:
        - name: PODNAME
          valueFrom: 
            fieldRef:
              fieldPath: metadata.name
        - name: nginx_conf
          value: |-
            user  nginx;
            worker_processes  1;

            error_log  /var/log/nginx/error.log warn;
            pid        /var/run/nginx.pid;

            events {
                worker_connections  1024;
            }
            http {
              server {
                listen 80;

                location / {
                  default_type text/plain;
                  return 200 '${PODNAME}';
                }
              }
            }
        command:
        - '/bin/sh'
        - '-c'
        - 'echo $nginx_conf > /nginx.conf.template && envsubst < /nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g "daemon off;"'
