05. Deploy demo app with persistence volume and publish app via ingress controller
Overview
Step-by-step guide on how to deploy demo application on HI GIO Kubernetes
Install nginx ingress controller to your Kubernetes cluster. Installing the nginx ingress controller will auto-create 2 Virtual services (80, 443) in HI GIO LB.
Deploy demo app with persistence volume into the Kubernetes cluster and publish app via ingress nginx
Procedure
1. Pre-requisites:
Helm (v3 or higher)
Make sure there is at least 1 available public IP
Have a default Storage Class
Permission for access to your Kubernetes cluster
2. Procedure:
Step 1: Install nginx ingress controller to your Kubernetes cluster
#Add repo ingress-nginx
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update ingress-nginx
#Install ingress nginx
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx \
--set controller.service.appProtocol=false \
--create-namespace
Verify pod status is
Runningand serviceingress-nginx-controllersuccessfully obtained anEXTERNAL IP
kubectl get all -n ingress-nginx
Step 2: Deploy demo app with persistence volume into the Kubernetes cluster and publish app via ingress nginx
Demo app folder structure
demoapp
├── 01-demoapp-namespace.yaml
├── 02-demoapp-pvc.yaml
├── 03-demoapp-deployment.yaml
├── 04-demoapp-service.yaml
└── 05-demoapp-ingress.yamlCreate file
01-demoapp-namespace.yamlto create demoapp namespace
apiVersion: v1
kind: Namespace
metadata:
name: demoappCreate file
02-demoapp-pvc.yamlto create a Persistence 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 classCreate file
03-demoapp-deployment.yamlto create the demoapp deployment
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-pvcCreate file
04-demoapp-service.yamlto create demoapp service
apiVersion: v1
kind: Service
metadata:
name: demoapp
namespace: demoapp
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 8080
selector:
app: demoappCreate file
05-demoapp-ingress.yamlto create demoapp ingress
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: PrefixApply all manifests
cd demoapp
kubectl apply -f .
Create a DNS record for demoapp
Name: <ingress-host>
Address: 42.113.xx.xx (EXTERNAL-IP of ingress nginx)
If all the configuration is correct, you can access your app with the domain
http://<ingress-host>

Last updated

