Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 2.18 KB

03-deploy-microservice.md

File metadata and controls

89 lines (64 loc) · 2.18 KB

Deploy The Microservice

Create Namespace

First of all you have to create the demo namespace:

kubectl apply -f kubernetes/namespace.yaml

Deploy The microservice Docker Image

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

Access Pod from outside the cluster

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

Invoke Microservice Health Endpoint

After that, you can invoke the health endpoint with

curl http://localhost:8080/actuator/health

Kubernetes Healthchecks

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