0

https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#expose Does not have required documentation

kubectl expose deployment hello-minikube --type=NodePort --port=8080 --target-port=30006
service/hello-minikube exposed

$ kubectl get svc 
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
hello-minikube   NodePort    10.110.117.25    <none>        8080:30751/TCP    21s
bhargav joshi
  • 329
  • 3
  • 6

1 Answers1

0

You are confusing Target Port, Nodeport and Port.

Here you can find perfect explanation what the difference is.

Use nodePort instead of target-port. And more convenient way to expose your application is to create and apply yaml:

apiVersion: v1
kind: Service
metadata:
  name: hello-minikube
spec:
  type: NodePort
  ports:
  - name: hello-minikube
    port: 8080
    targetPort: 8080
    nodePort: 30006
  selector:
    run: hello-minikube
Vit
  • 7,740
  • 15
  • 40