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

443 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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.