Kubernetes Run Command

KubernetesKubernetesBeginner
Practice Now

Introduction

The kubectl run command in Kubernetes is used to create and manage deployments, jobs, and other resources. It allows users to run containers with specified images and configurations in a Kubernetes cluster. In this lab, we will explore how to use the kubectl run command for different use cases, from simple to complex scenarios.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL kubernetes(("`Kubernetes`")) -.-> kubernetes/BasicCommandsGroup(["`Basic Commands`"]) kubernetes/BasicCommandsGroup -.-> kubernetes/get("`Get`") kubernetes/BasicCommandsGroup -.-> kubernetes/run("`Run`") subgraph Lab Skills kubernetes/get -.-> lab-8456{{"`Kubernetes Run Command`"}} kubernetes/run -.-> lab-8456{{"`Kubernetes Run Command`"}} end

Creating a Deployment

In this step, we will create a simple deployment using the kubectl run command. Here are the steps:

  1. Run the following command to create a pod with a single replica running the nginx container image:
kubectl run nginx-pod --image=nginx
  1. Verify that the pod has been created successfully by checking the status using the following command:
kubectl get pods

Creating a Job

In this step, we will create a job using the kubectl run command. Here are the steps:

  1. Run the following command to create a job that runs a container with the busybox image and performs a simple task, such as printing a message:
kubectl run job1 --image=busybox --restart=OnFailure -- echo "Hello from Job 1"
  1. Verify that the job has been created successfully by checking the status using the following command:
kubectl get pod job1

Summary

In this lab, we explored different use cases of the kubectl run command in Kubernetes. We learned how to create and manage deployments, create jobs. The kubectl run command is a powerful tool for managing containers in a Kubernetes cluster and provides flexibility and ease of use for various container deployment scenarios.

Other Kubernetes Tutorials you may like