Read Aloud the Text Content
This audio was created by Woord's Text to Speech service by content creators from all around the world.
Text Content or SSML code:
Welcome back. In the previous step, we created the container image for our Currency Exchange service. Let's try and deploy it right now. So, I'll copy the container image that we have created and pushed and let's go into our command prompt. I've already connected with the Google Cloud and I have already established connection with the Kubernetes cluster as well. And if I type in kubectl --version. Oops, it should be kubectl version. I can see the client version and the server version, so that's cool. Now, I would go ahead and say kubectl. We'd want to make a deployment. So, create deployment currency-exchange and --image is equal to the image that we have copied just now. So, in28min/mmv2-currency-exchange-service:0.0.11-SNAPSHOT. So, let's go ahead and create the deployment. In addition to the deployment, we would want to create a service as well. We'd want to expose it to the outside world. So, what we need to do is to say, expose deployment currency-exchange. The type of the deployment is load balancer, so --type=Load Balancer and we need to specify the port as well. So, the port on which we want to run Currency Exchang is 8000. Oops! There is a small change that I need to make in here. It should be t with a small t. So, --type=LoadBalancer --port=8000. Let's see if we get this right. So, let's see if these services launch up fine. So, kubectl get svc. So, the service is of type load balancer, the external IP is still pending. So, let's wait for it to get assigned. As you can see in here, I used a shortcut. So, svc is a shortcut for kubectl get service. So, instead of doing service or services, I can do a svc. And similarly with pods, instead of doing get pods, you can do a get po and similarly, instead of doing kubectl get replicaset, you can do a kubectl get rs. So, these are all the shortcuts you can use, but as long as you are new to Kubernetes, I would recommend you to use the full forms. So, use kubectl get replicaset, get pods, get services until you get completely familiar with them. Once you're familiar with them, then using shortcuts is awesome. And let's do a kubectl get all to see the status of everything that we have created. So, you can see the replica sets, pods, you can see the services, and I can see that the external IP is assigned. So, let's pick up this external IP. Now, I'd want to launch up Cloud Shell. If you are on Mac or Linux, then you can actually do the curl from your local machine itself. However, for people who are on Windows, they can launch up Cloud Shell so that they can get access to the terminal and they can launch commands from there. So, let's launch it up from here. So, I'll go into a full screen mode by clicking this and it would open it up in the new tab. I don't really want this, so I'll close this and use the one from the new window. Let's do a clear and this is where we can do a curl. Where do we need to do the curl to? So, this is the IP address, external IP which we got and I'll replace localhost in the currency-exchange URL with the external IP and curl to that. Let's see if this succeeds. Cool! I'm getting a response back, that looks awesome. So, I'm able to curl this. Now, what I would recommend you to do is to pause the video in here and try deploying the other one, the Currency Conversion as an exercise. Now, the commands to deploy Currency Conversion should be very, very similar. Right. So, all that I need to do is to say create deployment and go in here and I would need to change currency-exchange to currency-conversion and the image also we have created with the same tag. So, I just need to change exchange to conversion. So, make sure that you get this right. Typos can be costly in here. So, make sure that you get it absolutely right. The next thing I would need to do is to expose it out. So, expose deployment currency- conversion --type=LoadBalancer --port is equal to, this is one thing you should be careful about. We always expose our Currency Conversion on port 8100. So, let's go ahead and do that. Now, let's see the status. kubectl get service. What's happening with the service? The external IP is still pending. So, let's do a kubectl get service --watch. Let's wait for the external IP to be assigned. OK, the external IP is in here. So, it's 34.67.33.185 and let's go into the urls.txt and pick up the URL currency-conversion-feign one and replace localhost with this and fire a request. Let's do a curl to this. Awesome. I'm able to get the response back. There are a few interesting things that you would see in the response. There is a specific string that is being returned in the response and you can see v11 in the response as well. So, everything looks hunky dory. Now, there might be a couple of questions in your mind. Now, let's go back to our CurrencyConversionProxy. CurrencyConversion, oops, actually it's CurrencyExchangeProxy. Let's open that up, CurrencyExchangeProxy. So over here, there is an environment variable we are looking for, CURRENCY_EXCHANGE_SERVICE_HOST and if it's not present, we are using localhost and on Kubernetes, the call is working. How is it working? The reason why it's working is because this environment variable is automatically created on Kubernetes. So, what is happening on Kubernetes is, we have created a service with a name currency-exchange and we also have other services which are present, right? So, currency-service, currency-conversion, for example, or let's say you create other services with name, service-name. What Kubernetes does is, it makes a few environmental variables automatically available. So, currency, let's s ay I have these services present. Then whenever a new service starts up, these environment variables would be created, CURRENCY_EXCHANGE with all caps using underscore. It will create another environment variable for CURRENCY_CONVERSION. It will create another one for the other service, let's call it SERVICE_NAME and at the end of it, it would append this. So. _SERVICE_HOST So, these are the environment variables which are automatically created by Kubernetes whenever you launch up a new pod. So, whenever you launch up a new pod, all the existing services information is made available to the pod as environment variables. So, that's awesome and that's the thing that we made use of in here. So, if you look at the configuration that we have in here, so CURRENCY_EXCHANGE_SERVICE_HOST, so that's the one which we are making use in here. So, CURRENCY_EXCHANGE_ SERVICE_HOST and that's the reason why it's important that our service name was currency- exchange. If you had any other service name for Currency Exchange, this environment variable will not be useful. Now, that's one of the interesting things. The other interesting thing is what is this. right, currency-exchange this specific thing? What is this? Let's do a Control + C in here and let's do a kubectl get pods. Oops, let me get this right, kubectl get pods. So, over here, you can look at what is the pod name for currency-exchange, 686bbff8dc and compare it against this. You can see that these are exactly the same. So, this is nothing but the pod name. So, how are we getting it? Currency ExchangeController is where that's the code for that is. So, the pod name is made available as another enviornment variable and the environment variable name is HOSTNAME. So, this container, this microservice is running in a container in a specific pod, and we can get the pod information by getting the hostname and that's what we have configured and returned as host and that's the reason why we are now able to see it in here. This is how we are getting this information and to this information, the Currency Conversion service is appending feign. In this step, we made significant progress. In this specific step, we deployed both Currency Exchange and Currency Conversion services to Kubernetes. There are a lot of things that we need to talk about these services.