Home > Blockchain >  Can't access an application deployed on AKS
Can't access an application deployed on AKS

Time:02-15

I'm trying to access a simple Asp.net core application deployed on Azure AKS but I'm doing something wrong.

This is the deployment .yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: aspnetapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aspnet
  template:
    metadata:
      labels:
        app: aspnet
    spec:
      containers:
      - name: aspnetapp
        image: <my_image>
        resources:
            limits:
              cpu: "0.5"
              memory: 64Mi
        ports:
        - containerPort: 8080

and this is the service .yml

apiVersion: v1
kind: Service
metadata:
  name: aspnet-loadbalancer
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  selector:
    name: aspnetapp

Everything seems deployed correctly

enter image description here

Another check I did was to enter the pod and run curl http://localhost:80, and the application is running correctly, but if I try to access the application from the browser using http://20.103.147.69 a timeout is returned.

What else could be wrong?

CodePudding user response:

In your Deployment, you configured your container to listen on port 8080. You need to add targetport value set to 8080 in the Service definition.

Documentation

CodePudding user response:

Seems that you do not have an Ingress Controller deployed on your AKS as you have your application exposed directly. You will need that in order to get ingress to work.

To verify if your application is working your can use port-forward and then access http://localhost:8080 :

kubectl port-forward aspnetapp 8080:8080

But you should def. install a ingress-controller: Here is a Workflow from MS to install ingress-nginx as IC on your Cluster.

You will then only expose the ingress-controller to the internet and could also specify the loadBalancerIP statically if you created the PublicIP in advance:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup # only needed if the LB is in another RG
  name: ingress-nginx-controller
spec:
  loadBalancerIP: <YOUR_STATIC_IP>
  type: LoadBalancer

The Ingress Controller then will route incoming traffic to your application with an Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  ingressClassName: nginx # ingress-nginx specifix
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80

PS: Never expose your application directly to the internet, always use the ingress controller

  • Related