VOOZH about

URL: https://thenewstack.io/kubernetes-app-deployment-from-the-command-line/

⇱ Kubernetes App Deployment from the Command Line - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-01-14 06:00:25
Kubernetes App Deployment from the Command Line
tutorial,
Cloud Native Ecosystem / Kubernetes

Kubernetes App Deployment from the Command Line

Here is how to deploy a NGINX-based application directly from the Kubernetes command line.
Jan 14th, 2023 6:00am by Jack Wallen
👁 Featued image for: Kubernetes App Deployment from the Command Line

If you’ve been following my Kubernetes 101 series, you may have discovered that there are ways to make Kubernetes considerably easier. Thanks to MicroK8s and Portainer, the journey doesn’t have to be challenging all the time. But even though you can begin your dive into Kubernetes as a point-and-click affair with Portainer, at some point you might want to be able to work from the command line. That’s not a given but you never know if you’ll be thrown into a situation where you’re asked to deploy an app or service to a Kubernetes cluster and there is no Portainer GUI to be found.

Should such a situation arise, you’ll be glad you know how to take control of the command line interface and get the job done.

That’s exactly what we’re going to do here. We’ll run through a simple NGINX deployment and do it all from the command line.

Requirements

To follow along, you’ll need a running Kubernetes cluster, which is very easy to deploy with the help of MicroK8s. You can find out how to install MicroK8s here and then how to add nodes to the cluster here. Now, because we’re demonstrating with a MicroK8s version of Kubernetes, the commands will be a bit different because they’ll use microk8s along with kubectl.

That’s all you need. Let’s get to the deployment.

How to Create Your First Deployment

The first thing we’ll do is log in to the Kubernetes controller node. Once logged in, verify your nodes are all still connected with the command:

microk8s kubectl get nodes

The output of the command should contain something like this:

k8s3   Ready    <none>   23d   v1.24.8-2+1dda18a15eea38
k8s2   Ready    <none>   23d   v1.24.8-2+1dda18a15eea38
k8s1   Ready    <none>   23d   v1.24.8-2+1dda18a15eea38

Now that you’re certain your nodes are all in the Ready state, create a new directory with the command:

mkdir ~/deployment

Change into that newly-created directory with the command:

cd ~/deployment

Create a new deployment YAML file with:

nano nginx-deployment.yml

In that file, paste the following contents:


apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
– name: nginx
image: nginx:1.7.9
ports:
– containerPort: 80

Most of the above file should be self-explanatory, but there are certain sections to pay close attention to, such as:

  • apiVersion – details which version of the API will be used.
  • kind – details the type of object you are creating.
  • metadata – data that helps identify the object.
  • spec – the state you desire for the object

Save and close the file with the [Ctrl]+[X] keyboard shortcut.

Apply the newly created YAML file with the command:

microk8s kubectl apply -f nginx-deployment.yml

The output should show something like this:

deployment.apps/nginx-deployment created

Verify the deployment with:

microk8s kubectl get deployments

You should see something like this in the output:

nginx-deployment 2/2 2 2 5m32s

Awesome. Let’s keep going.

You’ll now need to find out what IP address for which the NGINX pod can be reached. One thing to keep in mind is that this first deployment will only be available to the local network. We’ll take that a step further next time and make it available outside the cluster.

To locate the IP address of the NGINX pod, issue the command:

microk8s kubectl describe  pods nginx

In the output, you should see something like this:

IPs:
IP: 10.1.219.7

Our NGINX pod is running on IP address 10.1.219.7. We can test that by running the following command from the controller node:

curl 10.1.219.7

The output should look something like this:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at"
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

If your controller node has a GUI, you can open a web browser and point it to http://10.1.219.7 and see the NGINX Welcome Page printed.

Now, if you’ve followed my previous articles and installed Portainer to the Microk8s cluster, you can log into Portainer, go to Applications, and see our nginx-deployment is available (Figure 1).

👁 Image

Figure 1: Our nginx-deployment is running.

Click on the listing and you’ll see that the pod has been replicated to two nodes (Figure 2).

👁 Image

Figure 2:  Our NGINX deployment is not just running on a single node, but two.

This, of course, isn’t very useful, as you cannot reach the app from outside of the cluster. That’s OK, because next time around we’re going to go back to Portainer and find out how easy it is to deploy the same NGINX application, only make it visible from outside of the cluster. And even though deploying such an application is far easier with a tool like Portainer, it’s always good to know how to deploy from the command line as well.

Of course, it’s always best to work smarter, not harder… which is exactly what Portainer will help us achieve.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.