Deploy Microservices

Deploy customer

Make sure you have setup the project/namespace

kubectl create namespace tutorial
kubectl config set-context $(kubectl config current-context) --namespace=tutorial

Then clone the git repository

git clone https://github.com/rafabene/istio-tutorial
cd istio-tutorial

Start deploying the microservice projects, starting with customer

Make sure istioctl is in your PATH:

$ istioctl version
client version: 1.2.2
citadel version: 1.2.2
egressgateway version: 1.2.2
galley version: 1.2.2
ingressgateway version: 1.2.2
pilot version: 1.2.2
policy version: 1.2.2
sidecar-injector version: 1.2.2
telemetry version: 1.2.2

Deploy Customer

You will deploy docker images that were privously built. If you want to build customer visit: Build Customer

Now let’s deploy the customer pod with its sidecar

kubectl apply -f <(istioctl kube-inject -f customer/kubernetes/Deployment.yml) -n tutorial
kubectl create -f customer/kubernetes/Service.yml -n tutorial

Expose customer

Since the customer service is the one our users will interact with, let’s add an OpenShift Route that exposes that endpoint.

kubectl create -f customer/kubernetes/Gateway.yml -n tutorial

kubectl get pods -w -n tutorial
If your pod fails with ImagePullBackOff, it’s possible that your current terminal isn’t using the proper Docker Environment. See Setup environment.

Wait until the status is Running and there are 2/2 pods in the Ready column. To exit, press Ctrl+C

Deploy Preference

You will deploy docker images that were privously built. If you want to build preference visit: Build Preference

Now let’s deploy the preference pod with its sidecar

kubectl apply -f <(istioctl kube-inject -f preference/kubernetes/Deployment.yml)  -n tutorial
kubectl create -f preference/kubernetes/Service.yml -n tutorial

Wait preference to be deployed

kubectl get pods -w -n tutorial

Wait until the status is Running and there are 2/2 pods in the Ready column. To exit, press Ctrl+C

Deploy Recommendation

You will deploy docker images that were privously built. If you want to build recommendation visit: Build Recommendation

Now let’s deploy the recommendation pod with its sidecar

kubectl apply -f <(istioctl kube-inject -f recommendation/kubernetes/Deployment.yml) -n tutorial
kubectl create -f recommendation/kubernetes/Service.yml -n tutorial
kubectl get pods -w -n tutorial

Wait recommendation to be deployed

Wait until the status is Running and there are 2/2 pods in the Ready column. To exit, press Ctrl+C

Test the customer endpoint

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

curl $(minikube ip):$INGRESS_PORT/customer

it should now return

customer => preference => recommendation v1 from '99634814-sf4cl': 1

Updating Redeploying Code

When you wish to change code (e.g. editing the .java files) and wish to "redeploy", simply:

cd {servicename}/java/{quarkus|springboot|vertx}

vi src/main/java/com/redhat/developer/demos/{servicename}/{Servicename}{Controller|Verticle}.java

Make your changes, save it and then:

mvn clean package
eval $(minikube docker-env)
docker build -t example/{servicename}:v1 .

kubectl get pods -o jsonpath='{.items[*].metadata.name}' -l app={servicename}
kubectl get pods -o jsonpath='{.items[*].metadata.name}' -l app={servicename},version=v1
kubectl delete pod -l app={servicename},version=v1 -n tutorial{namespace-suffix}

Why the delete pod?

Based on the Deployment configuration, Kubernetes/OpenShift will recreate the pod, based on the new docker image as it attempts to keep the desired replicas available

kubectl describe deployment {servicename} -n tutorial{namespace-suffix} | grep Replicas