Install Workload
Install Custom Three-Layer Application
This section deploys a three-layer application (React frontend, Django backend, Postgres database) based on this blog, adapted for Kubernetes and NDB.
Create Database Schema and Data
- Apply application secrets:
- Download and edit the ConfigMap:
Update
curl -LO https://raw.githubusercontent.com/nutanix-japan/ocp-gitp/main/docs/ocp_ndb/k8s/app-variables.yaml
DB_HOST
andDB_PORT
inapp-variables.yaml
: - Apply the ConfigMap:
- Run the Django job to populate the database:
- Monitor the job: Example output:
- Check job logs:
- Verify new tables:
Expected output: ~11 tables (e.g.,
auth_user
,django_migrations
).
Install Frontend and Backend
- Deploy Django and React applications:
- Verify pods:
Create Ingress for Access
-
Create an Ingress resource to replace OpenShift Routes:
cat << EOF > ingress.yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: flower-app namespace: ndb annotations: traefik.ingress.kubernetes.io/router.entrypoints: web traefik.ingress.kubernetes.io/router.pathmatcher: PathPrefix spec: rules: - host: flower.apps.k8suserXX.ntnxlab.local http: paths: - path: / pathType: Prefix backend: service: name: react-cluster-ip-service port: number: 80 - path: /admin pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 - path: /api pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 - path: /static/admin/ pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 - path: /static/rest_framework/ pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 - path: /static/ pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 - path: /media/ pathType: Prefix backend: service: name: django-cluster-ip-service port: number: 80 EOF
-
Replace
k8suserXX
with your user ID: -
Apply the Ingress:
-
Verify if Ingress resources are created
Test Frontend React Application
- Update your local hosts file:
- Access the React app:
- Log in with:
- Username: admin
- Password: admin_password
- Use the sliders to predict flower names.
Test Backend Django Application
- Access the Django admin:
- Log in with:
- Username: admin
- Password: admin_password
- Add a new user:
- Username: xyz-user
- Password: your_password
- Save and test the new user in the React app.
Check Postgres Database Data
- Connect to the database:
- Query users: Expected output:
Takeaways
- The NDB Operator simplifies VM-based database deployment in Kubernetes.
- Databases are provisioned via YAML manifests and exposed as Kubernetes Services.
- Security is managed with
securityContext
instead of SCCs, ensuring non-root execution.
Cleanup (optional)
kubectl delete -f ingress.yaml -n ndb
kubectl delete -f https://raw.githubusercontent.com/nutanix-japan/ocp-gitp/main/docs/ocp_ndb/k8s/react-deployment.yaml -n ndb
kubectl delete -f https://raw.githubusercontent.com/nutanix-japan/ocp-gitp/main/docs/ocp_ndb/k8s/django-deployment.yaml -n ndb
kubectl delete -f https://raw.githubusercontent.com/nutanix-japan/ocp-gitp/main/docs/ocp_ndb/k8s/django-job.yaml -n ndb
kubectl delete -f app-variables.yaml -n ndb
kubectl delete -f https://raw.githubusercontent.com/nutanix-japan/ocp-gitp/main/docs/ocp_ndb/k8s/app-secrets.yaml -n ndb
kubectl delete -f database.yaml -n ndb
kubectl delete -f ndbserver.yaml -n ndb
kubectl delete -f your-db-secret.yaml -n ndb
kubectl delete -f your-ndb-secret.yaml -n ndb
kubectl delete pod psql -n ndb
kubectl delete namespace ndb
helm uninstall ndb-operator -n ndb-operator
kubectl delete namespace ndb-operator
Decommission the Postgres database in the NDB UI.