skip to Main Content

I deployed my containerized application to google kubernetes engine using Ansible.

I created a pod for the application with using a deployment, I also specified containerPort as 8080. This seems to be working fine.

- name: Create k8s pod for nginx
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: v1
      kind: Deployment
      metadata:
        name: "{{ app }}"
        namespace: "{{ namespace }}"
        labels:
          app: "{{ app }}"
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: "{{ app }}"
        template:
          metadata:
            labels:
              app: "{{ app }}"
          spec:
            containers:
              - name: hello-dashboard
                image: "{{ image_name }}"
                # This app listens on port 8080 for web traffic by default.
                ports:
                  - containerPort: 8080
                env:
                  - name: PORT
                    value: "8080"

Tracking the deployment

kubectl get deployments --namespace=nginx

shows the deployment is READY and AVAILABLE

NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           34m

checking the pods created by the deployment

kubectl get pods --namespace=nginx

this also shows the pod was creates

NAME                    READY   STATUS    RESTARTS   AGE
nginx-cb894bfc5-trnrk   1/1     Running   0          33m

Now, when i check for the LoadBalancer service

kubectl get services --namespace=nginx

The service was also created and assigned an external-ip

NAME    TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)        AGE
nginx   LoadBalancer   10.99.240.181   35.242.130.109   80:31005/TCP   33m

But the problem is I can’t access the deployed application using the external-ip from the LoadBalancer, the browser tells me it cannot be reached.

2

Answers


  1. I think there is some mismatch in ports like an application running port_no inside the containers with the service(service.yaml) port and target port configuration

    Login or Signup to reply.
  2. Most likely this is an issue with your Kubernetes Service or Deployment. GKE will automatically provision the firewall rules required for the ports mapped to the Service resource.

    Ensure that you have exposed the correct port on your Service and mapped it to a valid port on your Deployment’s Pods. Also note, that the firewall required is for port 31005 (the nodePort) since this is the one that is accepting traffic from the load balancer.

    Ensure you allow incoming traffic as follows :

    1. From the internet to the load balancer on TCP port 8080.

    2. From the load balancer to all Kubernetes nodes on TCP port 31005.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search