Cannot access Web API deployed in Azure ACS Kubernetes Cluster

7/26/2018

Please help. I am trying to deploy a web API to Azure ACS Kubernetes cluster, it is a simple web API created in VSTS and the result should be like this: { "value1", "value2" }.

I plan to make the type as Cluster-IP but I want to test and access it first that is why this is LoadBalancer, the pods is running and no restart (I think it's good).

The guide I'm following is: Running Web API using Docker and Kubernetes

NAME                TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)            AGE
kubernetes          ClusterIP      10.0.0.1       <none>         443/TCP            3d
sampleapi-service   LoadBalancer   10.0.238.155   102.51.223.6      80:31676/TCP   1h

When I tried to browse the IP 102.51.223.6/api/values it says:

"This site can’t be reached"

service.yaml

kind: Service
apiVersion: v1
metadata:
  name: sampleapi-service
  labels:
    name: sampleapi
    app: sampleapi
spec:
  selector:
    name: sampleapi
  ports:
   - protocol: "TCP"
     # Port accessible inside the cluster
     port: 80
     # Port to forwards inside the pod
     targetPort: 80
     # Port accessible oustide the cluster
     #nodePort: 80
  type: LoadBalancer

deployment.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sampleapi-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: sampleapi
    spec:
      containers:
      - name: sampleapi
        image: mycontainerregistry.azurecr.io/sampleapi:latest
        ports:
        - containerPort: 80

POD

Name:           sampleapi-deployment-498305766-zzs2z
Namespace:      default
Node:           c103facs9001/10.240.0.4
Start Time:     Fri, 27 Jul 2018 00:20:06 +0000
Labels:         app=sampleapi
                pod-template-hash=498305766
Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"sampleapi-deployme
-498305766","uid":"d064a8e0-9132-11e8-b58d-0...
Status:         Running
IP:             10.244.2.223
Controlled By:  ReplicaSet/sampleapi-deployment-498305766
Containers:
  sampleapi:
    Container ID:   docker://19d414c87ebafe1cc99d101ac60f1113533e44c24552c75af4ec197d3d3c9c53
    Image:          mycontainerregistry.azurecr.io/sampleapi:latest
    Image ID:       docker-pullable://mycontainerregistry.azurecr.io/sampleapi@sha256:9635a9df168ef76a6a27cd46cb15620d762657e9b57a5ac2514ba0b9a8f47a8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 27 Jul 2018 00:20:48 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mj5m1 (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-mj5m1:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mj5m1
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     <none>
Events:
  Type    Reason                 Age   From                   Message
  ----    ------                 ----  ----                   -------
  Normal  Scheduled              50m   default-scheduler      Successfully assigned sampleapi-deployment-498305766-zzs2z to c103facs9001
  Normal  SuccessfulMountVolume  50m   kubelet, c103facs9001  MountVolume.SetUp succeeded for volume "default-token-mj5m1"
  Normal  Pulling                49m   kubelet, c103facs9001  pulling image "mycontainerregistry.azurecr.io/sampleapi:latest"
  Normal  Pulled                 49m   kubelet, c103facs9001  Successfully pulled image "mycontainerregistry.azurecr.io/sampleapi:latest"
  Normal  Created                49m   kubelet, c103facs9001  Created container
  Normal  Started                49m   kubelet, c103facs9001  Started container
-- jravenger4
asp.net-core-webapi
azure
docker-compose
kubernetes

1 Answer

7/26/2018

It seems like to me that your service isn't set to a port on the container. You have your targetPort commented out. So the service is reachable on port 80 but the service doesn't know to target the pod on that port.

-- Pablo Marti Cordero
Source: StackOverflow