0

Hi I have the following service definition...

apiVersion: v1
kind: Service
metadata:
  name: my-app-dev
  labels:
    run: my-app-dev
spec:
  type: NodePort
  selector:
    app: my-app-dev
  ports:
    - port: 18080
      targetPort: 18080
      name: http
    - port: 47100
      targetPort: 47100
      name: ignite-com
    - port: 47500
      targetPort: 47500
      name: ignite-disc

Then I run kubctl get svc which returns...

my-app-dev     NodePort    10.xxx.xxx.xxx   <none>        18080:32058/TCP,47100:30524/TCP,47500:31437/TCP   12m

When I try curl http://ip to kube agent:32058 I get curl: (7) Failed to connect to xxxxxx port 32058: Connection refused

But then I run, kubectl expose deployment my-app-dev --name=my-app-dev-2 --type=NodePort --port=18080 --target-port=18080

Which then kubctl get svc returns...

my-app-dev     NodePort    10.xxx.xxx.xxx   <none>        18080:32058/TCP,47100:30524/TCP,47500:31437/TCP   12m
my-app-dev-2   NodePort    10.xxx.xxx.xxx    <none>        18080:30571/TCP                                   11s

And curl http://ip to kube agent:30571 works perfectly fine. My minimum config seems right to me, but i could be wrong...

Update adding my deployment yaml in case I missed something...

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: my-app-dev
  name: my-app-dev
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-app-dev
  template:
    metadata:
      labels:
        run: my-app-dev
    spec:
      containers:
        - name: private
          image: foo/bar
          volumeMounts:
            - name: config-data
              mountPath: /config
          ports:
            - containerPort: 18080
              protocol: TCP
              name: http
            - containerPort: 47100
              protocol: TCP
              name: ignite-com
            - containerPort: 47500
              protocol: TCP
              name: ignite-disc
          env:
            - name: JAVA_OPTS
              value: "-Xms512m -Xmx512m -XX:+UseG1GC -XX:MaxInlineLevel=18 -Djava.net.preferIPv4Stack=true"
            - name: HOST
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
      initContainers:
        - name: config-data
          image: curlimages/curl
          command: ["sh", "-c", "TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`; curl -k -H \"Authorization: Bearer $TOKEN\" https://kubernetes.default:443/api/v1/namespaces/default/services/my-app-dev >> /config/service.json"]
          volumeMounts:
            - name: config-data
              mountPath: /config
      volumes:
        - name: config-data
          emptyDir: {}

user432024
  • 4,392
  • 8
  • 49
  • 85
  • Does the Service's `selector:` match the Pods' `metadata: { labels: }`? (IME the easiest way to check this is the last line of the `kubectl describe service` output; it should not say `Endpoints: `.) – David Maze Jul 21 '23 at 01:38
  • You are correct the ones defined by yaml have no endpoint, while the one from kubectl has one. But when I look at my definitions they look correct, the labels match etc... I'll update my deployment yaml above just to be sure... – user432024 Jul 21 '23 at 01:56
  • I mean I added my yaml deployment config above. It looks right to me... – user432024 Jul 21 '23 at 02:05
  • 1
    Ok I found it. The selector in the service uses app label while I use run everywhere else... Copy and paste from the internets lol – user432024 Jul 21 '23 at 02:45

0 Answers0