skip to Main Content
  • I have dockerized a simple spring boot rest api app which lists the
    employees for /employee endpoint.

  • I have created a helm chart and updated the values.yml with the image
    name, service type as NodePort and service port as 31234.

  • The app is configured to run on port 8085

  • Created a local docker registry in localhost 5001 and pushed the
    image to this registry. So the image name under values.yml is localhost:5001/emp and tag is latest.

  • kubectl get nodes -o wide gives:

test-dev-control-plane Ready control-plane 2d23h v1.27.3 172.18.0.3 Debian GNU/Linux 11 (bullseye) 5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1

test-dev-worker Ready 2d23h v1.27.3 172.18.0.5 Debian GNU/Linux 11 (bullseye) 5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1

test-dev-worker2 Ready 2d23h v1.27.3 172.18.0.2 Debian GNU/Linux 11 (bullseye) 5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1

  • kubectl get services:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

emp1-chart NodePort 10.96.181.143 31234:30296/TCP 2d19h
kubernetes ClusterIP 10.96.0.1 443/TCP 2d23h

  • kubectl get pods:

NAME READY STATUS RESTARTS AGE

abc 1/1 Running 1 (6m20s ago) 2d19h

  • So when I try these url they are not working:

http://172.18.0.2:31234/employee

http://172.18.0.3:31234/employee

http://172.18.0.5:31234/employee

I can see the image in the node using the commands:

  • kubectl get nodes
  • docker exec -ti test-dev-worker bash
  • crictl images

It lists the image:

localhost:5001/employee1 latest f784fbf148a06 532MB

helm chart values.yml:

replicaCount: 1
image:
  repository: localhost:5001/employee1
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "latest"
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Automatically mount a ServiceAccount's API credentials?
  automount: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""
podAnnotations: {}
podLabels: {}
podSecurityContext: {}
  # fsGroup: 2000
securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000
service:
  type: NodePort
  port: 31234
ingress:
  enabled: false
  className: ""
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local
resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #   cpu: 100m
  #   memory: 128Mi
  # requests:
  #   cpu: 100m
  #   memory: 128Mi
autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80
# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
#   secret:
#     secretName: mysecret
#     optional: false
# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
#   mountPath: "/etc/foo"
#   readOnly: true
nodeSelector: {}
tolerations: []
affinity: {}

2

Answers


  1. Chosen as BEST ANSWER

    This worked for me :)

    kubectl port-forward <pod-name> <local-port>:<remote-port>
    kubectl port-forward pods/abc 31234:8085
    

    Where abc is my pod name, 31234 is the NodePort defined in helm chart values.yml which maps to the container port in my deployment.yml and 8085 is the port defined as server port in my spring boot rest api app.

    Once I did that, I could see this as output:

    Forwarding from 127.0.0.1:31234 -> 8085
    Forwarding from [::1]:31234 -> 8085
    Handling connection for 31234
    Handling connection for 31234
    

    Then I ran my app using http://localhost:31234/employee This gave me the results I was looking for :)


  2. Instead of the kubectl port-forward command, adding targetPort as 8085 to the service section would have worked too. Something like below:

    service:
      type: NodePort
      port: 31234
      targetPort: 8085
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search