deployment and exposing app on kubernetes

9/11/2019

On Ubuntu, I used minikube to deploy and expose an app onto kubernetes. I ran into a problem on how I can use and view the app.

I used this link to resolve this issue.

minikube service --url $SERVICE

I expect the output to display the app I deployed on kubernetes.

The actual output from google chrome when I click on the link in ubuntu terminal is:

This site can’t be reached 
192.168.99.108 refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

Here is the pod definition:

priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-6sw9l
    secret:
      defaultMode: 420
      secretName: default-token-6sw9l
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2019-09-21T22:50:02Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2019-09-23T22:05:36Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2019-09-23T22:05:36Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2019-09-21T22:50:02Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: 
docker://57c0d2fccc9698ace22600f3d3197416324ed3bf570f929562d4669bd018d77f
    image: .../test:latest
    imageID: docker-pullable://.../test@sha256:fc6e42ba94b04cafa64c77b76961243695e03441ce0a54d21f22db99c8fdf7d7
        lastState:
          terminated:
            containerID: docker://e5ed21b41e7075681d6be8b46954e8bb5b2e6be2ef63942951b41176d583f03e
            exitCode: 0
            finishedAt: "2019-09-23T21:44:21Z"
            reason: Completed
            startedAt: "2019-09-23T21:43:40Z"
        name: test
        ready: true
        restartCount: 3
        state:
          running:
            startedAt: "2019-09-23T22:05:28Z"
      hostIP: 10.0.2.15
      phase: Running
      podIP: 172.17.0.9
      qosClass: BestEffort
      startTime: "2019-09-21T22:50:02Z"

Here is the service definition:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2019-09-21T22:50:13Z"
  labels:
    app: tesb-node
  name: tesb-node
  namespace: default
  resourceVersion: "51502"
  selfLink: /api/v1/namespaces/default/services/tesb-node
  uid: d0182ca7-cbd0-4c56-a2b7-a9e6f1c64621
spec:
  clusterIP: 10.99.98.201
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30178
    port: 84
    protocol: TCP
    targetPort: 84
  selector:
    app: tesb-node
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer: {}
-- BZM708
kubernetes
kubernetes-pod

4 Answers

9/12/2019

You need to pass NodePort number with ip to receive response. Can to try

kubectl get service $SERVICE --output='jsonpath="{.spec.ports[0].nodePort}"'

to get the port number?

-- Bimal
Source: StackOverflow

9/26/2019

As we can see in your pod definition there is no containerPort in your container spec, add it and everything should work.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80
-- jt97
Source: StackOverflow

9/30/2019

I made changes and updated the yaml file in deployment on minikube dashboard like this:

"spec": {
    "containers": [
      {
        "name": "test",
        "image": ".../test",
        "ports": [
          {
            "containerPort": 84,
            "protocol": "TCP"
          }
        ],
        "resources": {},
        "terminationMessagePath": "/dev/termination-log",
        "terminationMessagePolicy": "File",
        "imagePullPolicy": "Always"
      }

Then I used this command in ubuntu terminal:

minikube service tesb-node

And the output is this:

This site can’t be reached192.168.99.108 refused to connect.
Search Google for 192 168 108 30178
ERR_CONNECTION_REFUSED

Is there something I missed or doing wrong?

-- BZM708
Source: StackOverflow

10/12/2019

I used the following code in terminal:

kubectl describe svc tesb-node | grep Endpoints

The output for endpoints is:

Endpoints:               172.17.0.22:84
-- BZM708
Source: StackOverflow