How to create a kubernetes workload and expose it in same command line?

6/8/2021

In a kubernetes cluster we can create a workload and expose it in two separate commands.

  1. kubectl run deployment-name --image=imagename
  2. kubectl expose deployment deployment-name --port=port --type=type --name=name

Could we do it in one command?

-- Aditya Bhuyan
kubectl
kubernetes
workload

1 Answer

6/8/2021

This could be achieved by the below command. It will create a workload and also expose it in same time.

kubectl run nginx-digital --image=nginx --expose=true --port=80

The above command will create a deployment nginx-digital and also expose it with ClusterIP service with name nginx-digital at port 80.

-- Aditya Bhuyan
Source: StackOverflow