Answers: <p>Prior to apps/v1 the selector field was implicitly picked up from the pod template's labels. So in your case it would be:</p>
  
  <pre><code>spec:
    selector:
      matchLabels:
        io.kompose.service: web
  </code></pre>
  
  <p>Starting with apps/v1 an explicit selector field is required by the Kubernetes API.</p>
  
  <p>I would suggest not to change the iptables on your own as it it the responsibility of your Kubernetes network plugin and is most likely done well.</p>
  
  <p>As far as I am concerned you may simple update the Deployment manifest and no uninstall is required.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-19T04:39:18.910Z
Answers: OK, so being a bit new to K8s, if I simply change the deployment yaml file that would do it? so kubernetes continually checks that file and makes the appropriate changes to the deployment? Should I be changing the service yaml as well?
Answers: trimonkeytri
Answers: CC BY-SA 4.0
Answers: 2019-11-19T12:13:00.790Z
Answers: @trimonkeytri No, if you change the yaml file you have to tell kubernetes that it changed.  _kubectl apply -f deployment.yaml_ or delete and recreate the resource.
Answers: Matthew
Answers: CC BY-SA 4.0
Answers: 2019-11-19T23:19:27.400Z
Answers: I ran the kubectl apply command and got this error - "error: unable to recognize "cart-deployment.yaml": no matches for kind "Deployment" in version "extensions/v1beta1" so I changed the API version to app/v1 and got this error - "error: error validating "cart-deployment.yaml": error validating data: [ValidationError(Deployment.spec.selector.matchLabels): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchLabels: got "string", expected "map", unknown object type "nil" in Deployment.spec.template.metadata.labels.io.kompose.service];"
Answers: trimonkeytri
Answers: CC BY-SA 4.0
Answers: 2019-11-20T12:26:41.830Z
Answers: This sounds like an error with yaml formatting/indentations.
Answers: luki
Answers: CC BY-SA 4.0
Answers: 2019-11-21T22:35:06.147Z
Answers: Hmm? I did spaces and not tabs. Not sure what else to do?
Answers: trimonkeytri
Answers: CC BY-SA 4.0
Answers: 2019-11-27T22:19:47.907Z
Answers: Did you figure out the issue? If not please the yaml file contents. Also please tell which k8s version are you using.
Answers: luki
Answers: CC BY-SA 4.0
Answers: 2019-11-18T22:35:54.193Z
Answers: 2019-11-18T22:35:54.193Z
Answers: luki
Body: <p>I'm working with yaml files built for an older version of the API</p>
  
  <pre><code>apiVersion: extensions/v1beta1
  </code></pre>
  
  <p>I tried changing to </p>
  
  <pre><code>apiVersion: apps/v1 
  </code></pre>
  
  <p>But couldn't figure out the correct "selector" formatting. So I changed back to v1beta1</p>
  
  <p>Then I ran across this command:</p>
  
  <pre><code>kubectl convert -f . | kubectl -n robot-shop create -f -
  </code></pre>
  
  <p>All seemed to deploy correctly. But now when I try to reach my app, I get connection refused. After some investigation, I took a look at iptables and see this:</p>
  
  <pre><code>iptables -L | grep 30080
  REJECT     tcp  --  0.0.0.0/0            0.0.0.0/0            
  /* robot-shop/web:8080 has no endpoints */ ADDRTYPE match 
  dst-type LOCAL tcp dpt:30080 reject-with icmp-port- 
  unreachable
  </code></pre>
  
  <p>After some more research, this seems to have something to do with kube-proxy and "selector".</p>
  
  <p>Question is, what's the right course of action? <br>
  1. Change the fw rule to ACCEPT<br>
  2. make the correct changes to yaml file (need help with that)<br>
  &emsp;a. If so, do I delete the deployment and then make correct changes, then redeploy?</p>
  
  <p><br><br>
  Here's my deployment yaml file:</p>
  
  <pre>
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    annotations:
      kompose.cmd: kompose -f ../docker-compose.yaml convert
      kompose.version: 1.10.0 (8bb0907)
    creationTimestamp: null
    labels:
      io.kompose.service: web
    name: web
  spec:
    replicas: 1
    strategy: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          io.kompose.service: web
      spec:
        containers:
        - image: linuxacademycontent/rs-web:latest
          name: web
          ports:
          - containerPort: 8080
          resources:
            limits:
              cpu: 200m
              memory: 100Mi
            requests:
              cpu: 100m
              memory: 50Mi
        restartPolicy: Always
  status: {}
  </pre>
  
  <p>And my service yaml file:</p>
  
  <pre>
  apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kompose.cmd: kompose -f ../docker-compose.yaml convert
      kompose.version: 1.10.0 (8bb0907)
    creationTimestamp: null
    labels:
      io.kompose.service: web
    name: web
  spec:
    type: NodePort
    ports:
    - name: "8080"
      port: 8080
      targetPort: 8080
      nodePort: 30080
    selector:
      io.kompose.service: web
  status:
    loadBalancer: {}
  </pre>
  
Comments: CC BY-SA 4.0
Comments: 2019-11-18T20:47:19.287Z
Comments: In short, do NOT just tweak iptables to make your stuff work. Editing stuff like this outside of kubernetes is asking for headaches. Please add some more detail to what you've done and what you're trying to do.  If you can, post the yaml so we can see what's going on.  My guess from what you've said is that the selector in your Service description is out of sync with your Deployment.
Comments: Matthew
Comments: CC BY-SA 4.0
Comments: 2019-11-18T21:18:09.063Z
Comments: I updated my question with the yaml file. It doesn't have the selector field as it was built for an older version of the API where it wasn't required. That's my issue.
Comments: trimonkeytri
Comments: CC BY-SA 4.0
Comments: 2019-11-18T23:01:45.677Z
Comments: You spec'd a containerPort of 8080 but when you looked at iptables you grep'd for 30080.  I assume you have a Service as well? What's that look like?
Comments: Matthew
Comments: CC BY-SA 4.0
Comments: 2019-11-19T04:57:55.533Z
Comments: I updated my question with the service yaml file
Comments: trimonkeytri
Tags: <kubernetes>
Title: Kubernetes - Deploying older version of app in new API
UserDisplayName: trimonkeytri
ThreadText: # Kubernetes - Deploying older version of app in new API
  
  (Asked by: username_0 on 2019-11-18)
  
  I'm working with yaml files built for an older version of the API
  
  ```
  apiVersion: extensions/v1beta1
  
  ```
  
  I tried changing to
  
  ```
  apiVersion: apps/v1 
  
  ```
  
  But couldn't figure out the correct "selector" formatting. So I changed back to v1beta1
  
  Then I ran across this command:
  
  ```
  kubectl convert -f . | kubectl -n robot-shop create -f -
  
  ```
  
  All seemed to deploy correctly. But now when I try to reach my app, I get connection refused. After some investigation, I took a look at iptables and see this:
  
  ```
  iptables -L | grep 30080
  REJECT     tcp  --  0.0.0.0/0            0.0.0.0/0            
  /* robot-shop/web:8080 has no endpoints */ ADDRTYPE match 
  dst-type LOCAL tcp dpt:30080 reject-with icmp-port- 
  unreachable
  
  ```
  
  After some more research, this seems to have something to do with kube-proxy and "selector".
  
  Question is, what's the right course of action?   
  1. Change the fw rule to ACCEPT  
  2. make the correct changes to yaml file (need help with that)  
   a. If so, do I delete the deployment and then make correct changes, then redeploy?
  
  Here's my deployment yaml file:
  
  ```
  
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    annotations:
      kompose.cmd: kompose -f ../docker-compose.yaml convert
      kompose.version: 1.10.0 (8bb0907)
    creationTimestamp: null
    labels:
      io.kompose.service: web
    name: web
  spec:
    replicas: 1
    strategy: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          io.kompose.service: web
      spec:
        containers:
        - image: linuxacademycontent/rs-web:latest
          name: web
          ports:
          - containerPort: 8080
          resources:
            limits:
              cpu: 200m
              memory: 100Mi
            requests:
              cpu: 100m
              memory: 50Mi
        restartPolicy: Always
  status: {}
  
  ```
  
  And my service yaml file:
  
  ```
  
  apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kompose.cmd: kompose -f ../docker-compose.yaml convert
      kompose.version: 1.10.0 (8bb0907)
    creationTimestamp: null
    labels:
      io.kompose.service: web
    name: web
  spec:
    type: NodePort
    ports:
    - name: "8080"
      port: 8080
      targetPort: 8080
      nodePort: 30080
    selector:
      io.kompose.service: web
  status:
    loadBalancer: {}
  
  ```
  
  **Tags:** kubernetes
  
  > **Comments:**
  > **username_1**: In short, do NOT just tweak iptables to make your stuff work. Editing stuff like this outside of kubernetes is asking for headaches. Please add some more detail to what you've done and what you're trying to do.  If you can, post the yaml so we can see what's going on.  My guess from what you've said is that the selector in your Service description is out of sync with your Deployment.  
  > **username_0**: I updated my question with the yaml file. It doesn't have the selector field as it was built for an older version of the API where it wasn't required. That's my issue.  
  > **username_1**: You spec'd a containerPort of 8080 but when you looked at iptables you grep'd for 30080.  I assume you have a Service as well? What's that look like?  
  > **username_0**: I updated my question with the service yaml file  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-11-18. Score: 1
  
  Prior to apps/v1 the selector field was implicitly picked up from the pod template's labels. So in your case it would be:
  
  ```
  spec:
    selector:
      matchLabels:
        io.kompose.service: web
  
  ```
  
  Starting with apps/v1 an explicit selector field is required by the Kubernetes API.
  
  I would suggest not to change the iptables on your own as it it the responsibility of your Kubernetes network plugin and is most likely done well.
  
  As far as I am concerned you may simple update the Deployment manifest and no uninstall is required.
  
  > **Comments:**
  > **username_0**: OK, so being a bit new to K8s, if I simply change the deployment yaml file that would do it? so kubernetes continually checks that file and makes the appropriate changes to the deployment? Should I be changing the service yaml as well?  
  > **username_1**: @username_0 No, if you change the yaml file you have to tell kubernetes that it changed.  _kubectl apply -f deployment.yaml_ or delete and recreate the resource.  
  > **username_0**: I ran the kubectl apply command and got this error - "error: unable to recognize "cart-deployment.yaml": no matches for kind "Deployment" in version "extensions/v1beta1" so I changed the API version to app/v1 and got this error - "error: error validating "cart-deployment.yaml": error validating data: [ValidationError(Deployment.spec.selector.matchLabels): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchLabels: got "string", expected "map", unknown object type "nil" in Deployment.spec.template.metadata.labels.io.kompose.service];"  
  > **username_2**: This sounds like an error with yaml formatting/indentations.  
  > **username_0**: Hmm? I did spaces and not tabs. Not sure what else to do?  
  > **username_2**: Did you figure out the issue? If not please the yaml file contents. Also please tell which k8s version are you using.  
  
  ---
  
  