Many modern applications consist of a containerized part of the application stack that still has a dependency on data services that are better suited to VM based form factors then containers. In this solution, we will take a look at deploying a VM based MySQL database that will be accessed by a API server (backend). A consumer will access the application using a the UI (frontend), both the backend and frontend applications will be running as containers inside of a Kubernetes cluster.
All yaml files can be found in the codeSamples directory.
Login to the Supervisor using kubectl vsphere login -s <CP_VM_IP>
Check storage class name kubectl describe ns <YOUR_NAMESPACE>
Resource Quotas
Name: developer-utilities-storagequota
Resource Used Hard
-------- --- ---
vsan-default-storage-policy.storageclass.storage.k8s.io/requests.storage 0 9223372036854775807
wcpglobal-storage-profile.storageclass.storage.k8s.io/requests.storage 0 9223372036854775807
kubectl get vmclass -n <YOUR_NAMESPACE>
(see example)
NAME CPU MEMORY AGE
best-effort-small 2 4Gi 7d2h
best-effort-medium 4 8Gi 7d2h
best-effort-large 4 16Gi 7d2h
STORAGE_CLASS: vsan-default-storage-policy
VM_CLASS: best-effort-small
kubectl get virtualmachineimages -n <YOUR_NAMESPACE>
NAME CONTENTSOURCENAME VERSION OSTYPE FORMAT AGE
ob-19930037-photon-3-k8s-v1.22.9---vmware.1-tkg.1.cc71bc8 226a0b09-167d-49cf-b36a-4b2cb6e519c9 v1.22.9+vmware.1-tkg.1.cc71bc8 vmwarePhoton64Guest ovf 8d
ubuntu-20-1633387172196 81747b37-03b5-4936-98d3-f5032315bfdc ubuntu64Guest ovf 4m22s
Base64 encode the mysql_config and add it to the user-data field in the mysql-db-cm ConfigMap (mysql-vm.yaml) cat mysql_config.yaml | base64 -w0
Update mysql_vm.yaml to leverage the storage class and vm class listed above (mysql-vm.yaml).
kubectl apply -f mysql_vm.yaml -n <YOUR_NAMESPACE>
Update the tkg.yaml file to use the correct tkr, storageClass, and vmClass.
Deploy the TKG cluster kubectl apply -f tkg.yaml -n <YOUR_NAMESPACE>
Use kubectl watch tkc tkc-workload-cluster -n <YOUR_NAMESPACE>
to track when the cluster is ready.
Note: There are 3 additional fields in the backend-app-secret that contain values associated with the MySQL Database. Only change them if you made an update to the MySQL Database or the mysql-config.yaml.
Get the mysql-db LoadBalancer External IP kubectl get service mysql-db -n <YOUR_NAMESPACE>
Base64 encode the external IP address and add it to the ‘backend-app-secret’ for the mysql_host field (backend-app.yaml) echo -n "192.12.34.6" | base64 -w0
login to the TKG Cluser ‘kubectl vsphere login –server
Select the TKG cluster context kubect config use-context workload-cluster
Apply the Pod Security Policy kubectl apply -f pod-security-policy.yaml
Create a namespace kubectl create ns app-ns
Deploy the Backend Container kubectl apply -f backend-app.yaml -n app-ns
Wait for the Backend application pod to be started watch kubectl get pods -n app-ns
Once Backend applicaiton pod is started, get the external IP from the backend-app-service kubectl get service -n app-ns
Test backend application curl -X GET <EXTERNAL-IP>:5000/api/index
, one entry should be returned.
Base64 encode the external IP address and port 5000 from above and add it to the ‘frontend-app-secret’ for the api_url field (frontend-app.yaml) echo -n "187.12.34.5:5000" | base64 -w0
Deploy the Frontend-application kubectl apply -f frontend-app.yaml -n app-ns
Wait for the frontend application pod to be started watch kubectl get pods -n app-ns
Once frontend applicaiton pod is started, get the external IP from the frontend-app-service kubectl get service -n app-ns
Copy the external IP address and add port 5000 `Example: 192.26.35.25:5000 and paste into your browser. You will be directed to the Home page of the application.