1

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: {}
4
  • 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.
    – Matthew
    Nov 18, 2019 at 20:47
  • 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. Nov 18, 2019 at 21:18
  • 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?
    – Matthew
    Nov 18, 2019 at 23:01
  • I updated my question with the service yaml file Nov 19, 2019 at 4:57

1 Answer 1

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.

6
  • 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? Nov 19, 2019 at 4:39
  • @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.
    – Matthew
    Nov 19, 2019 at 12:13
  • 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];" Nov 19, 2019 at 23:19
  • This sounds like an error with yaml formatting/indentations.
    – luki
    Nov 20, 2019 at 12:26
  • Hmm? I did spaces and not tabs. Not sure what else to do? Nov 21, 2019 at 22:35

Your Answer

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

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