Hello and welcome to this demo on deploying an application to Oracle Kubernetes Engine. I'm Mahendra Mehra and I'm a Senior Training lead and evangelist with Oracle University. As part of this demo, we will be seeing how to deploy a Python Flask application on the Oracle Kubernetes cluster that we just created. To remind you, in the previous demos, we have already created the oracle Container Registry, we have also created the Oracle Kubernetes cluster and we have set up the Cloud Shell access to our Oracle Kubernetes cluster. As part of this demo, we will be creating a local application in Python. We will be then creating a Docker image out of it, and storing it on the container registry. Later we will be using the Cube CTL command in order to deploy our application on the Oracle Kubernetes cluster. Let's get started. I'm in my Cloud Shell and I'll be creating a Python application for the demonstration purpose. Since I'm creating a Python Flask application, let me quickly go ahead and install Flask. The Flask is already installed in my Cloud Shell. Let me quickly create a directory to hold all my code. The directory is created. Let me switch into directory using the CD command. Let me create a Python application, hello.py. This is my application code which is running a server on port 5,000 and once you connect to this server on port 5,000 it will return hello world from Flask. Let me quickly save this. Once we have created the application, let's quickly run it on the local machine. Let me export some environment variables before I run this application. I'm setting flask_app environment variable as the name of my file and setting flask_environment variable as development. Now let's run the application. My application is started on port 5,000. Let me open up another Cloud Shell and using the Curl command, try to hit this URL. The Cloud Shell instances up. Let me quickly run the Curl command. Let me hit "Enter". As you can see, the application is just running fine. While I connect to the port 5,000 on my machine, it's returning me a string hello world from flask which it is supposed to. Let me switch back to the first tab and close the application. Let me clear the screen. Now that I've tested my application locally, let me quickly create a Docker image of my application, for which I'll be using the Docker file. Let's start writing a Docker file. Before that, I must ensure that I'm in my workspace directory. Yes, I'm currently in Python, Hello app. So let me quickly create a Docker file. This is the content of my Docker file. I'm using the from instruction to tell the Docker engine to use the Python base image then I'm using the add instruction to add the hello dot.py file from my current directory into the root directory of my base image. Then I'm using the Copy command to copy all the files into the slash app directory on the base image. Then I'm switching my work directory to /app. I'm also using the run command to install Flask within the image using P3. Then I'm using the Expose command to expose port 5,000 on the image. Finally, I'm using the CMD command to tell the Docker engine to run hello.py application whenever the image is containerized. Let me close this. Now, we need to build a Docker image using the Docker build command. I'll be using the Docker build command to build the image using Docker file. Let me hit "Enter". As you can see, the Steffen is downloading the base image. The step two, three, four are subsequently copying my hello.py file into the app directory and making app directory the current working directory. Then the exposed command to expose port 5,000. Finally the CMD to tell Docker engine to run the hello.py file whenever the image is containerized. Let's quickly check if the image is created using the docker images command. Great, so the Python-hello-app images created for my application. Before we deploy this image on the cluster, let's test it locally using the Docker run command. This Docker run command will containerize the Python Hello app by mapping port 5,000 of the container to put 5,000 of my local machine. Again, we're using ampersand at the end to run it in the background. The RM flag over your instructs the Docker Engine to remove the container once the container is exited. Let me go ahead and hit "Enter". Our server has started. Let me quickly switch to the next tab and hit the "Curl command" to see if the port 5,000 of my local machine is mapped to the container 5,000 and I'm still able to see the string. Let me run the Curl command. Great. As you can see, the port 5,000 of my local machine is mapped to port 5,000 of the container which is running and it is displaying the content of the application. To also show you that the container is running, let me do a docker PS command just to confirm, the Docker container is running in the background. Great. Now I can stop this container and push the Docker image into the container registry on the UCI. The docker stop command will stop the container. As you can see, the container has stopped. Remember, once I stop the container, the container will be auto-deleted from the system since we provided the RM flag in the docker run command. It's time to push this image to the OCI Container Registry. Let me quickly take you to the Container Registry that we created in our previous demo. By clicking on the "Hamburger menu", go into the Developer Services, and clicking on the "Container Registry". As you can see in the current compartment, I have one repository with one image in it. This is what we had created in the previous demo. Let me quickly create a new repository for this application. I've given my repository name and I'll click on Create Repository. I leave the access as private. Great. Now I have a new repository within my container registry with no image in it. Let me quickly go back to the Cloud shell and push the image that we just created. First, let me log in into the Container Registry using Docker login command. It is asking for the username. I'll hit Enter and then as password you have to enter the odd token. Remember I had already created an odd token in the previous demo, I'll be using the same. In case you have lost your odd token, you need to create a new one in the user settings. I've successfully logged in into Docker Container Registry. Before pushing the image to the Container Registry, I need to tag the local image with the URL for the registry plus the repo name, and then I'll push it to the Container Registry. Let me write the Docker tag command. This is my Docker tag command where the source image name is the name of the image that I have in my local registry, and then I'm tagging it with the URL of my Container Registry, with the repo name as created earlier. Let me quickly go ahead and hit Enter. I have tagged the image. To see the changes, I write the Docker image command. As you can see, a new tag has been created for the same image. Now, we will push this image onto the OCI Container Registry. This is the Docker push command that I'll be using to push the image that I just tagged onto the OCI Container Registry. As you can see, the image is being pushed and the push has been completed. Now, let us quickly go to the Container Registry and see if we can find the image in the OCI Container Registry. Let me quickly hit a refresh, and click on the repository. Awesome. As you can see, the image has been pushed into the repository on my Oracle Container Registry. The next step is to deploy this image on the OKE clusters. The first thing that we will be doing is to create a registry secret for the application. This secret authenticates our image, when we deploy it to the cluster. To create a secret, we will be using the Kubectl create secret command. This is the command to create the secret. Using Kubectl create secret we will be creating an OCI secret for our Docker Registry, where we need to provide these values. Values like, the region for our Docker Container Registry, the Docker username, which is the tendency name space slash the username. The password is basically the token that we had generated earlier, and then you have to specify the email. I'll go ahead and hit Enter. The output says the secret has been created. To verify if the secret is created, we can issue the following command. Let me hit Enter. The output on the screen indicates that the secret has been created successfully. Let me clear the screen. Now let me create a Kubernetes manifest for deployment. This is basically a YAML file. This is my Kubernetes deployment manifest. I need to replace this with the host URL of the image, which is present in my Container Registry. I've replaced it with the host URL where my image is present. The next thing that I need to change is the name of my image pull secret. The name of our secret was OCIR secret, so I'll place it here. Let me also tell you that this portion of our code is basically adding a flexible Load Balancer, so I'm adding a service of type Load Balancer. I have made changes to the deployment manifest, and I'll quickly save it. Now, it's time to deploy the application. To deploy the application, I'll be using the Kubectl create command. With this command, I'll be deploying the application on the Kubernetes cluster that we have created. Let me go ahead and hit Enter. Our deployment has been created, and the Load Balancer service is in place. To check if the load balancer is live, let's use the Kubectl get service command. As you can see, our Load Balancer is live, and this is the external IP on which we can connect to our Load Balancer. The port that is mapped is 5,000. Let me quickly use this IP and the port in order to connect to our application. Let me open up a new tab and hit this IP along with this port. Let's go ahead and hit Enter to see if our application is successfully deployed on the Oracle Kubernetes Engine cluster. That's great. We can see the application has been deployed successfully, as we can see the end result. We can also undeploy this application from our cluster using the Kubectl delete command. Let me go ahead and undeploy this application. The deployment and the services have been deleted. Now if I go back to this tab and hit Refresh, the web app is not responding as the deployment and the services are deleted. With this, we come to the end of this demo, where we successfully created a Hello World Python application using the plus framework. We created a Docker image of our application, which was then pushed to the Container Registry on OCI. We created a deployment manifest and deployed our application to the Oracle Kubernetes Engine cluster, and made it accessible on the Internet. I hope you liked the demo. See you in the next one. Thanks for watching.