Below is described how to facilitate application development in running in kubernetes.
-
Install Kubectl Client 1.13.
-
Install Minikube.
-
Optionally can use Skaffold project, to facilitate continuous development.
The diagram below depicts how enable multi cluster development in k8s:
Sample application that shows how to connect a frontend system with a backend in different clusters.
- Deploy backend application in remote cluster:
kubectl apply -f backend.yaml
- Make sure backend-* pod and service are up and running :
kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/backend-czn64 1/1 Running 1 7d5h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/backend-srv ClusterIP 100.70.181.149 <none> 80/TCP 7d5h
- Forward the backend service to localhost:
kubectl port-forward --address=192.168.99.1 $(kubectl get pod -l type=be-type -o jsonpath='{.items[0].metadata.name}') 2000:5000 &
- Check backend service via browser or curl:
curl http://192.168.99.1:2000/
- Deploy fronted application in minikube cluster:
kubectl apply -f frontend.yaml
- Make sure fe-* pod and service are up and running :
kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/frontend-dlghf 1/1 Running 1 11h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/frontend-srv ClusterIP 10.97.237.77 <none> 8000/TCP 11h
- Forward the frontend service to localhost:
kubectl port-forward $(kubectl get pod -l type=fe-type -o jsonpath='{.items[0].metadata.name}') 8000:8000 &
- Check frontend service is up and can forward requests to backend:
curl http://localhost:8000/
- Remove any kubectl port-forward processes that may still be running:
killall kubectl
- Uninstall backend application in remote cluster:
kubectl delete -f backend.yaml
- Deploy frontend application in minikube cluster:
kubectl delete -f frontend.yaml
Kubehelloworld project authored by Sal Rashid.
Opengov Devops team.