1

When I execute kubectl create deployment nginx --image nginx --dry-run=client -o yaml it does not have options --port or --containerPort. My yaml is:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

Is there a way to generate yaml with the containerPort option?

1 Answer 1

2

From the kubernetes docs I see this example:

$ echo 'apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: deployment-example
spec:
  replicas: 3
  revisionHistoryLimit: 10
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.11
        ports:
        - containerPort: 80
' | kubectl replace -f -

So under your containers entry you should be able to add:

        ports:
        - containerPort: 80

Is that what you had in mind or, at least, good enough? You seem to want this as a command line option for the kubectl command and I don't see anything that indicates this is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.