First of all you have to create the demo namespace:
kubectl apply -f kubernetes/namespace.yaml
Then, you can deploy the Docker Image with:
kubectl apply -f kubernetes/deployment.yaml
You can get the deployment with:
kubectl get deploy -l app=kube-demo -n demo
The replicaset:
kubectl get rs -l app=kube-demo -n demo
And the pod:
kubectl get pod -l app=kube-demo -n demo
You can see the pod log with:
POD=$(kubectl get pods -l app=kube-demo -n demo -o jsonpath='{.items[0].metadata.name}')
kubectl logs -f $POD -n demo
You can expose the microservice using port-forward:
POD=$(kubectl get pods -l app=kube-demo -n demo -o jsonpath='{.items[0].metadata.name}')
kubectl port-forward $POD 8080:8080 -n demo
After that, you can invoke the health endpoint with
curl http://localhost:8080/actuator/health
You can use the health endpoint to automatically check the microservice status with Kubernetes Liveness and Readiness Probes. To do this, you have to remove comments from lines 32-47 from kubernetes/deployment.yaml:
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 20
timeoutSeconds: 5
periodSeconds: 5
failureThreshold: 3
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 35
timeoutSeconds: 5
periodSeconds: 10
failureThreshold: 1
And redeploy the microservice with:
kubectl apply -f kubernetes/deployment.yaml