> For the complete documentation index, see [llms.txt](https://docs-epc.gitbook.io/ncs-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-epc.gitbook.io/ncs-documents/load-balancing/nginx-plus.md).

# Nginx Plus

## Nginx Plus คืออะไร

เอกสารที่เกี่ยวข้อง

* <https://www.f5.com/products/nginx/nginx-plus>

***

&#x20;

<figure><img src="https://t9003005656.p.clickup-attachments.com/t9003005656/1a7bdd80-2787-4fda-bfa2-bf6dce98bc06/image.png" alt=""><figcaption></figcaption></figure>

คือแพ็คเก็จระดับ enterprise grade ที่มีความสามารถทุกอย่างที่ Nginx open source ทำได้ อีกทั้งยังมีฟีเจอร์หลักที่ช่วยให้ระบบมี **High Availability (HA)** ที่ทั้ง **ปรับขยายได้ (scalable)** และ **เชื่อถือได้ (reliable)** พร้อมเครื่องมือสำหรับ **Monitoring** เพื่อช่วย **debug** และ **วิเคราะห์ปัญหา** ในสถาปัตยกรรมแอปพลิเคชันที่ซับซ้อน&#x20;

**Advanced security** ลดความเสี่ยงด้านความปลอดภัยด้วยฟีเจอร์ ดังนี้

* request and connection limiting เพื่อป้องกันปัญหา overload, abuse, หรือ DoS attack
* รองรับ protocol TLS1.3
* สามารถทำ dynamic certificate loading ได้ คือความสามารถที่ NGINX Plus สามารถ โหลดหรืออัปเดต SSL/TLS certificates ได้แบบไดนามิก (ขณะรันอยู่) โดย ไม่ต้อง reload หรือ restart NGINX process
* มีการใช้ JWT authentication&#x20;

**Best-of-breed support** มี assistance support สำหรับการช่วยเหลือ

* installation and deployment
* debugging and error correction
* security notifications
* software updates

**Load balancer** ที่ชาญฉลาด

* รองรับระบบขนาดใหญ่ (High scale) สำหรับ HTTP, TCP, UDP traffic
* มีการรองรับ Load Balancing Algorithms ที่หลากหลาย&#x20;

**API gateway** เป็นตัวกลางหรือ entry point ระหว่าง client กับ backend services หรือ microservices

* มีการทำ edge gateway with TLS termination และ rate limiting
* สามารถทำ request routing เพื่อกำหนดเส้นทาง route ของ request ว่าจะส่งไปยัง service backend ใด
* สามารถทำ request manipulation เพื่อปรับแต่ง request/response ให้ตรงตามเงื่อนไขหรือ policy&#x20;

**Reverse proxy** คือเซิร์ฟเวอร์กลางที่ รับ request จาก client แล้วส่งต่อไปยัง backend server

* Session persistence
* caching
* multiple algorithms to maximize speed and capacity for resiliency and scale&#x20;

## ขั้นตอนการติดตั้ง NGINX Plus Ingress Controller บน Kubernetes ด้วย Helm

ขั้นตอนการติดตั้ง NGINX Plus Ingress Controller บน Kubernetes Cluster โดยใช้ Helm Chart และค่า config ที่จำเป็น เอกสารที่เกี่ยวข้อง

* <https://docs.nginx.com/nginx-ingress-controller/installation/installing-nic/installation-with-helm/#configuration>

***

#### ขั้นตอนที่ 1 เตรียมข้อมูลยืนยันตัวตน (Authentication)

เริ่มต้นต้องสร้าง Kubernetes Secret เพื่อให้ Cluster สามารถยืนยันตัวตนและ pull image ของ NGINX Plus จาก Private Registry ของ NGINX ได้

1. **รับ Certificate/Key หรือ JWT Token** เข้าสู่ระบบที่ [my.f5.com](https://my.f5.com) เพื่อดาวน์โหลดไฟล์ `nginx-repo.crt` และ `nginx-repo.key` หรือคัดลอก JWT token สำหรับ Docker Registry
2. **สร้าง Kubernetes Secret:** รันคำสั่ง `kubectl` เพื่อสร้าง `docker-registry` secret ใน namespace ที่ต้องการ (ตัวอย่างนี้ใช้ `nginx-ingress`)

```bash
kubectl create secret docker-registry nginx-repo-secret \
    --namespace nginx-ingress \
    --docker-server=private-registry.nginx.com \
    --docker-username=<your-username> \
    --docker-password=<your-password-or-jwt> \
    --docker-email=<your-email>
```

> **Note:** หากยังไม่มี namespace `nginx-ingress` คุณสามารถสร้างก่อนด้วยคำสั่ง `kubectl create namespace nginx-ingress` หรือใช้ flag `--create-namespace` ในขั้นตอนการติดตั้ง Helm

***

#### ขั้นตอนที่ 2 เตรียมไฟล์คอนฟิกสำหรับ Helm (values.yaml)

เราจะใช้ Helm Chart อย่างเป็นทางการของ NGINX และทำการ override ค่าคอนฟิกบางส่วนเพื่อให้ชี้ไปยัง NGINX Plus

1. **เพิ่ม NGINX Helm repository:** หากยังไม่เคยเพิ่ม ให้รันคำสั่งต่อไปนี้

```bash
helm repo add nginx-ingress oci://ghcr.io/nginx/charts/nginx-ingress	
```

2. **สร้างไฟล์** **`values.yaml`\*\*\*\*:** สร้างไฟล์ใหม่ชื่อ `values.yaml` และใส่เนื้อหาดังนี้เพื่อเปิดใช้งาน NGINX Plus และระบุ Image ที่ถูกต้อง

```yaml
controller:
  appprotect:
    configManager:
      image:
        repository: registry.nipa.cloud/nap/waf-config-mgr
    enforcer:
      image:
        repository: registry.nipa.cloud/nap/waf-enforcer
  config:
    entries:
      allow-snippet-annotations: "true"
      client-max-body-size: 250m
      enable-underscores-in-headers: "true"
      error-log-level: debug
      large-client-header-buffers: 4 64k
      proxy-buffers: 128 4k
      redirect-to-https: "true"
      server-name-hash-bucket-size: "1024"
      ssl-redirect: "false"
      use-forwarded-headers: "true"
      worker-processes: "40"
  customConfigMap: null
  image:
    repository: registry.nipa.cloud/nginx-ic/nginx-plus-ingress
  nginxplus: true
  customPorts:
    - name: nginx-dashboard
      containerPort: 8080
      protocol: TCP

serviceInsight:
  create: true
```

***

#### ขั้นตอนที่ 3 ติดตั้งด้วย Helm

เมื่อเตรียม Secret และไฟล์ `values.yaml` เรียบร้อยแล้ว ก็สามารถติดตั้ง NGINX Plus Ingress Controller ได้ด้วยคำสั่ง `helm install`

```bash
helm install nginx-ingress-my-release nginx-ingress/nginx-ingress \
  --version 2.2.1 \
  --values xxxxxxx.yaml
```

* `nginx-ingress-my-release` คือชื่อ release ที่คุณตั้งเอง
* `nginx-ingress/nginx-ingress` คือ `[repo/chart]`
* `--version` ช่วยให้แน่ใจว่าใช้เวอร์ชันที่ต้องการ
* `--values` หรือ `-f` ใช้กำหนดไฟล์ค่า override **หลังจากรันคำสั่งนี้สำเร็จ NGINX Plus Ingress Controller จะถูกติดตั้งและพร้อมใช้งานใน Kubernetes Cluster ของคุณโดยจะได้เป็น service type loadbalancer โดย default**

```yaml
apiVersion: v1
kind: Service
metadata:
    name: nginx-dashboard
  namespace: nginx-ingress
spec:
  ports:
    - name: dashboard
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app.kubernetes.io/name: nginx-ingress
  type: ClusterIP
```
