Answers: <p>From <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#-strong-api-overview-strong-" rel="nofollow noreferrer">the kubernetes docs</a> I see this example:</p>
  
  <pre><code>$ 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 -
  </code></pre>
  
  <p>So under your <code>containers</code> entry you should be able to add:</p>
  
  <pre><code>        ports:
          - containerPort: 80
  </code></pre>
  
  <p>Is that what you had in mind or, at least, good enough?  You seem to want this as a command line option for the <code>kubectl</code> command and I don't see anything that indicates this is possible.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-04-29T13:43:48.827Z
Answers: 2020-04-29T13:43:48.827Z
Answers: chicks
Body: <p>When I execute <code>kubectl create deployment nginx --image nginx --dry-run=client -o yaml</code> it does not have options <code>--port</code> or <code>--containerPort</code>.  My yaml is:</p>
  
  <pre><code>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: {}
  </code></pre>
  
  <p>Is there a way to generate yaml with the <code>containerPort</code> option?</p>
  
Tags: <kubernetes><kubectl>
Title: kubectl create deployment not has the option containerPort
UserDisplayName: Afonso Rodrigues
ThreadText: # kubectl create deployment not has the option containerPort
  
  (Asked by: username_0 on 2020-04-29)
  
  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?
  
  **Tags:** kubernetes, kubectl
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-29. Score: 2
  
  From [the kubernetes docs](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#-strong-api-overview-strong-) 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.
  
  
  ---
  
  