Let's Run Our First Application
Explore deploying your first application on Kubernetes by applying a manifest file with kubectl. Understand how to run an nginx pod, check its status, and use port forwarding to access it locally. This lesson helps you start practical Kubernetes deployment with simple commands and hands-on experience.
We'll cover the following...
Deploying our first application
Before we start talking about all the things you can do with Kubernetes, let’s run a quick example, so you can see how things work in practice. Don’t worry if you don’t understand everything we are doing. We just want to show you that getting an application to run on Kubernetes is not that complicated.
As we’ll discuss later, we usually work with Kubernetes in a declarative way. Instead of telling it what to do, we send it a manifest (as a yaml file) describing our desired state. In this case, we want to run nginx, so the manifest would be something like this:
We’ll look into these manifest files in more detail later, so don’t worry about that for now. To send the manifest to Kubernetes, we will use the kubectl command-line tool that we already have installed for you.
Run the application below, and enter the following command:
kubectl apply -f nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx-container
image: nginxNote: Hit the “RUN” button before clicking on the app link.
You should see a message saying the nginx pod was created. Run the following command:
The ContainerCreating status means Kubernetes is downloading the nginx image so we can run it locally. After a few seconds, if you run this command again, you will see the pod is now in the Running state.
And that’s all we need to run an application with Kubernetes! Not that complicated, right?
But just seeing a Running state is not good enough. Let’s try to actually see this application in our browser to make sure it’s running fine.
We’ll later learn different ways to expose our applications so they can be accessed by other applications running in our Kubernetes cluster and by our users. But for now, let’s just forward the requests to this application:
kubectl port-forward nginx 3000:80
Note: To see the output in the output tab, you need to run the
port-forwardcommand. In order to run port forwarding on the platform, you need to include the--address 0.0.0.0flag in the port forwarding command, so the above command would now become:
kubectl port-forward --address 0.0.0.0 nginx 3000:80
We used kubectl again but now calling the port-forward command. It will take the name of our application that is nginx, and forwards the requests received locally on port 3000 to the container’s port, 80 (that’s the default port nginx is listening to).
Now, if you try to access the URL under the SPA widget, you should see the nginx welcome page similar to the one below.
Note: If the link is displaying some other page instead of the
nginxwelcome page, please refresh the page.