> For the complete documentation index, see [llms.txt](https://docs.higiocloud.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.higiocloud.vn/hi-gio-user-guide-vn/hi-gio-kubernetes/5.-trien-khai-ung-dung-demo-voi-persistence-volume-va-public-app-qua-ingress-controller.md).

# 5. Triển khai ứng dụng demo với persistence volume và public app qua ingress controller

## <mark style="color:green;">**Tổng quan**</mark> <a href="#overview" id="overview"></a>

*Hướng dẫn từng bước về cách triển khai ứng dụng demo trên HI GIO Kubernetes.*

* *Cài đặt nginx ingress controller vào cluster Kubernetes của bạn. Việc cài đặt nginx ingress controller sẽ tự động tạo 2 Virtual services (80, 443) trong HI GIO LB.*
* *Triển khai ứng dụng demo với persistent volume vào Kubernetes cluster và public app qua ingress nginx.*

## <mark style="color:green;">Quy trình</mark> <a href="#id-2.-guidance" id="id-2.-guidance"></a>

* Helm (v3 trở lên)
* Đảm bảo có ít nhất 1 IP public khả dụng
* Có một Storage Class mặc định
* Có quyền truy cập vào cluster Kubernetes của bạn

{% stepper %}
{% step %}
**Bước 1:** Cài đặt nginx ingress controller vào cluster Kubernetes của bạn

```
#Add repo ingress-nginx
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update ingress-nginx
```

<div align="left"><figure><img src="/files/AituNTE1DsLzXlOJvtJT" alt=""><figcaption></figcaption></figure></div>

```
#Install ingress nginx
helm install ingress-nginx ingress-nginx/ingress-nginx \
		--namespace ingress-nginx \
		--set controller.service.appProtocol=false \
		--create-namespace
```

<figure><img src="/files/NwcQ9yy04bQ2UKUzacQT" alt=""><figcaption></figcaption></figure>

* Xác minh trạng thái của pod là **Running** và service **ingress-nginx-controller** đã thành công lấy được **EXTERNAL IP**

```
kubectl get all -n ingress-nginx
```

<figure><img src="/files/FrhFuVNDMLzMy8nOSDQk" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
CNI driver trên Kubernetes tự động tạo Virtual services trên HI GIO LB và 2 DNAT rules (80, 443) trên vCD.

Vui lòng thay đổi firewall của VPC để cho phép truy cập vào các dịch vụ ảo của ingress. Điều này cung cấp quyền truy cập vào ứng dụng của bạn được publish qua nginx ingress.

Tham khảo: [Sử dụng Edge Gateway Firewall](/hi-gio-user-guide-vn/network/1.-lam-viec-voi-mang-network/su-dung-edge-gateway-firewall.md)
{% endhint %}
{% endstep %}

{% step %}
**Bước 2:** Triển khai ứng dụng demo với persistent volume vào Kubernetes cluster và public ứng dụng qua nginx ingress

* Cấu trúc thư mục ứng dụng demo

```
demoapp 
├── 01-demoapp-namespace.yaml
├── 02-demoapp-pvc.yaml
├── 03-demoapp-deployment.yaml
├── 04-demoapp-service.yaml
└── 05-demoapp-ingress.yaml
```

* Tạo file `01-demoapp-namespace.yaml` để tạo namespace cho demoapp

```
apiVersion: v1
kind: Namespace
metadata:
  name: demoapp
```

* Tạo file `02-demoapp-pvc.yaml` để tạo Persistent Volume Claim

```
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demoapp-pvc
  namespace: demoapp
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: default-storage-class-1 #adjust to use your storage class
```

* Tạo file `03-demoapp-deployment.yaml` để tạo deployment cho demoapp

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demoapp
  namespace: demoapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: demoapp
  template:
    metadata:
      labels:
        app: demoapp
    spec:
      containers:
      - name: demoapp
        image: paulbouwer/hello-kubernetes:1.8
        ports:
        - containerPort: 8080
        volumeMounts:
        - mountPath: /data
          name: demoapp-storage
      volumes:
      - name: demoapp-storage
        persistentVolumeClaim:
          claimName: demoapp-pvc
```

* Tạo file `04-demoapp-service.yaml` để tạo service cho demoapp

```
apiVersion: v1
kind: Service
metadata:
  name: demoapp
  namespace: demoapp
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: demoapp
```

* Tạo file `05-demoapp-ingress.yaml` để tạo ingress cho demoapp

```
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demoapp-ingress
  namespace: demoapp
spec:
  ingressClassName: nginx
  rules:
  - host: demoapp.cloud.net.vn #adjust to use your domain
    http:
      paths:
      - backend:
          service:
            name: demoapp
            port:
              number: 80
        path: /
        pathType: Prefix
```

* Áp dụng tất cả các manifests

```
cd demoapp
kubectl apply -f .
```

<div align="left"><figure><img src="/files/9YJOGE7njUKShSAipV2W" alt=""><figcaption></figcaption></figure></div>

* Tạo bản ghi DNS cho demoapp

```
Name: <ingress-host>
Address: 42.113.xx.xx  (EXTERNAL-IP của ingress nginx)
```

<div align="left"><figure><img src="/files/LkBlWTFiCF2oqMplY5Md" alt=""><figcaption></figcaption></figure></div>

* Nếu tất cả các cấu hình là chính xác, bạn có thể truy cập ứng dụng của mình qua tên miền

`http://<ingress-host>`

<figure><img src="/files/DbE6zTR0gQr9lqxkdKYh" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.higiocloud.vn/hi-gio-user-guide-vn/hi-gio-kubernetes/5.-trien-khai-ung-dung-demo-voi-persistence-volume-va-public-app-qua-ingress-controller.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
