• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Kubernetes

Running Docker Images on Kubernetes with kubectl run

June 26, 2024
in Kubernetes, Kubernetes Commands Examples, Kubernetes Commands Tutorial, Kubernetes Tutorial
A A
0
12
SHARES
109
VIEWS
Share on FacebookShare on Twitter

Kubectl is a powerful command-line tool for managing Kubernetes clusters. One of its key functionalities is the ability to deploy Docker images onto a Kubernetes cluster using the `run` option. This allows you to start a new deployment, replica set, or job using a Docker image.

Running Docker Images on Kubernetes with kubectl run

Example 1: Deploying a simple NGINX web server as a Deployment:

kubectl run nginx --image=nginx --replicas=3

This command creates a new Deployment named ‘nginx’ with 3 replicas using the NGINX Docker image. To verify, you can check the status of the Deployment:

kubectl get deployments
kubectl get pods

Example 2: Creating a Job to perform a batch task:

kubectl run batch-job --image=busybox --restart=OnFailure -- echo "Batch job completed"

This command creates a Job named ‘batch-job’ using the BusyBox image to echo a message. To verify, check the status of the Job:

kubectl get jobs
kubectl logs 

Example 3: Running a Pod with a specific command:

kubectl run test-pod --image=ubuntu --restart=Never --command -- sleep 3600

This creates a Pod named ‘test-pod’ using the Ubuntu image to sleep for 3600 seconds. To verify, check the status of the Pod:

kubectl get pods
kubectl logs 

Example 4: Running a Pod with environment variables:

kubectl run env-pod --image=nginx --env="MESSAGE=Hello, Kubernetes!"

This creates a Pod named ‘env-pod’ using the NGINX image with an environment variable set. To verify, inspect the Pod’s environment:

kubectl exec -it  -- env | grep MESSAGE

Example 5: Deploying a Redis instance as a StatefulSet:

kubectl run redis --image=redis --restart=Always --port=6379

This command creates a StatefulSet named ‘redis’ using the Redis image with port 6379 exposed. To verify, check the StatefulSet and its Pods:

kubectl get statefulsets
kubectl get pods

Example 6: Running a Pod with resource limits:

kubectl run resource-pod --image=busybox --restart=Never --limits='cpu=0.5,memory=512Mi'

This command creates a Pod named ‘resource-pod’ using the BusyBox image with specified CPU and memory limits. To verify, describe the Pod and check its resource limits:

kubectl describe pods 

Example 7: Creating a CronJob to run scheduled tasks:

kubectl run cron-job --image=busybox --schedule="*/1 * * * *" -- echo "Scheduled task executed"

This command creates a CronJob named ‘cron-job’ using the BusyBox image to echo a message every minute. To verify, check the status of the CronJob:

kubectl get cronjobs
kubectl logs 

Example 8: Running a Pod with a specific service account:

kubectl run sa-pod --image=busybox --restart=Never --serviceaccount=my-service-account

This command creates a Pod named ‘sa-pod’ using the BusyBox image with a specific service account ‘my-service-account’. To verify, inspect the Pod’s service account:

kubectl get pods sa-pod -o jsonpath='{.spec.serviceAccountName}'

Example 9: Deploying a Pod with labels:

kubectl run labeled-pod --image=nginx --labels="app=nginx,env=prod"

This command creates a Pod named ‘labeled-pod’ using the NGINX image with labels ‘app=nginx’ and ‘env=prod’. To verify, list Pods with the specified labels:

kubectl get pods --selector=app=nginx,env=prod

Example 10: Running a Pod with a specific namespace:

kubectl run namespace-pod --image=busybox --restart=Never --namespace=my-namespace

This command creates a Pod named ‘namespace-pod’ using the BusyBox image in the ‘my-namespace’ namespace. To verify, list Pods in the specific namespace:

kubectl get pods --namespace=my-namespace

Also check similar articles.

Expose Kubernetes Services Easily with kubectl expose
How to Create Kubernetes Resources from Files or Stdin
Overriding –databases Option in mysqldump
Creating Tab-Separated Output Files with mysqldump
Handling Failed SSL Session Data Reuse in mysqldump

Tags: KubernetesKubernetes Commands ExamplesKubernetes Commands TutorialKubernetes Tutorial
Previous Post

Expose Kubernetes Services Easily with kubectl expose

Next Post

Setting Features on Kubernetes Objects using kubectl set

Related You may like!

howto

Interacting with Kubernetes Plugins using kubectl plugin

June 26, 2024
howto

Configuring kubectl and kubeconfig Files

June 26, 2024

Exploring Kubernetes API Versions with kubectl api-versions

June 26, 2024

Understanding Kubernetes API Resources with kubectl api-resources

June 26, 2024

Generating Shell Completion Code with kubectl completion

June 26, 2024

Managing Kubernetes Annotations with kubectl annotate

June 26, 2024
Next Post
howto

Setting Features on Kubernetes Objects using kubectl set

howto

Understanding Kubernetes Resources with kubectl explain

howto

Comprehensive Guide to kubectl get Command

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.