apiVersion: v1
kind: ConfigMap
metadata:
  name: community-forms-nginx-v1
  namespace: default
data:
  nginx.conf: |
    user  nginx;
    worker_processes  1;
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events {
        worker_connections  1024;
    }

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;

        sendfile        on;
        #tcp_nopush     on;
        gzip on;
        gzip_disable "msie6";
        gzip_min_length 1k;
        gzip_buffers 16 64k;
        gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_vary on;
        gzip_types text/plain application/x-javascript application/javascript application/css  text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

        keepalive_timeout  65;

        server {
            listen 80 default_server;
            listen [::]:80 default_server;
            return 444;
        }

        server {
            listen 80;
            server_name forms.pingcap.com;

            location /healthz {
              return 200 'OK';
            }

            location / {
              return 302 https://pingkai.cn/forms$request_uri;
            }
        }
    }

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: community-forms
  namespace: default
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  selector:
    matchLabels:
      app: community-forms
  template:
    metadata:
      labels:
        app: community-forms
    spec:
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: ScheduleAnyway
        labelSelector:
          matchLabels:
            app: community-forms
      containers:
      - name: community-forms-nginx
        image: uhub.service.ucloud.cn/library/nginx:1.18.0
        livenessProbe:
          httpGet:
            path: /healthz
            port: 80
            httpHeaders:
              - name: Host
                value: forms.pingcap.com
          periodSeconds: 10
          initialDelaySeconds: 3
        volumeMounts:
        - name: nginx-config-volume
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: "2"
            memory: 2Gi
          requests:
            cpu: 500m
            memory: 256Mi
      volumes:
      - name: nginx-config-volume
        configMap:
          name: community-forms-nginx-v1

---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: community-forms
  name: community-forms
  namespace: default
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: community-forms

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 20m
  name: community-forms
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: forms.pingcap.com
    http:
      paths:
      - backend:
          service:
            name: community-forms
            port:
              number: 80
        path: /
        pathType: Prefix
  tls:
  - hosts:
    - forms.pingcap.com
    secretName: star-pingcap-com-2025-tls
