skip to Main Content

I am trying to expose a deployment I made on minikube:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-test
  labels:
    app: debian
spec:
  replicas: 1
  selector:
    matchLabels:
      app: debian
  strategy: {}
  template:
    metadata:
      labels:
        app: debian
    spec:
      containers:
      - image: agracia10/debian_bash:latest
        name: debian
        ports:
        - containerPort: 8006
        resources: {}
      restartPolicy: Always
status: {}

I decided to follow was is written on here

I try to expose the deployment using the following command:

kubectl expose pod deployment-test-8497d6f458-xxhgm --type=NodePort --port=8080 --target-port=80

but when I try to then access the service created by the expose command, using the url provided by

minikube service deployment-test-8497d6f458-xxhgm --url

it throws an error using packetsender to try and connect to the service:
packet sender log

Im not really sure what the reason for this could be, I think it has something to do with the fact that when I get the services it says on the external ip field. Also, when I try and retrieve the node IP using minikube ip it gives an address, but when the minikube service --url it gives the 127.0.0.1 address. In any case, using either one does not work.

2

Answers


  1. it’s not working due to a port configuration mismatch.

    You deployment container running on the 8006 but you have exposed the 8080 and your target port is : --target-port=80

    so due to this it’s not working.

    Ideal flow of traffic goes like :

    service (node port, cluster IP or any) > Deployment > PODs
    

    Below sharing the example for deployment and service

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: blog-app-server-instance
      labels:
        app: blog-app
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: blog-app
      template:
        metadata:
          labels:
            app: blog-app
        spec:
          containers:
          - name: agracia10/debian_bash:latest
            image: blog-app-server
            ports:
            - containerPort: 8006
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: blog-app-service
      labels:
        app: blog-app
    spec:
      selector:
        app: blog-app
      type: NodePort
      ports:
      - port: 80
        nodePort: 31364
        targetPort: 8006
        protocol: TCP
        name: HTTP
    

    so things I have changed are image and target port.

    Once your Node port service is up and running you will send the request on Port 80 or 31364

    i will redirect the request internally to the target port which is 8006 for the container also.

    Using this command you exposed your deployment on wrong target point

    kubectl expose pod deployment-test-8497d6f458-xxhgm --type=NodePort --port=8080 --target-port=80
    

    ideally it should be 8006

    Login or Signup to reply.
  2. As I know the simplest way to expose the deployment to service we can run this command, you don’t expose the pod but expose the deployment.

    kubectl expose deployment deployment-test --port 80
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search