visual studio kubernetes project 503 error in azure

8/21/2021

I have created a kubernetes project in visual studio 2019, with the default template. This template creates a WeatherForecast controller. After that I have published it to my ARC.

I used this command to create the AKS:

az aks create -n $MYAKS -g $MYRG --generate-ssh-keys --z 1 -s Standard_B2s --attach-acr /subscriptions/mysubscriptionguid/resourcegroups/$MYRG/providers/Microsoft.ContainerRegistry/registries/$MYACR

And I enabled HTTP application routing via the azure portal.

I have deployed it to azure kubernetes (Standard_B2s), with the following deployment.yaml:

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernetes1-deployment
  labels:
    app: kubernetes1-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kubernetes1
  template:
    metadata:
      labels:
        app: kubernetes1
    spec:
      containers:
      - name: kubernetes1
        image: mycontainername.azurecr.io/kubernetes1:latest
        ports:
        - containerPort: 80

service.yaml:

#service.yaml
apiVersion: v1
kind: Service
metadata:
  name: kubernetes1
spec:
  type: ClusterIP
  selector:
    app: kubernetes1
  ports:
    - port: 80 # SERVICE exposed port
      name: http # SERVICE port name
      protocol: TCP # The protocol the SERVICE will listen to
      targetPort: http # Port to forward to in the POD

ingress.yaml:

#ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes1
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
    - host: kubernetes1.<uuid (removed for this post)>.westeurope.aksapp.io # Which host is allowed to enter the cluster
      http:
        paths:
          - backend: # How the ingress will handle the requests
              service:
               name: kubernetes1 # Which service the request will be forwarded to
               port:
                 name: http # Which port in that service
            path: / # Which path is this rule referring to
            pathType: Prefix # See more at https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types

But when I go to kubernetes1.<hidden>.westeurope.aksapp.io or kubernetes1.<hidden>.westeurope.aksapp.io/WeatherForecast I get the following error:

503 Service Temporarily Unavailable
nginx/1.15.3
-- 1408786user
azure-aks
kubernetes
kubernetes-ingress

1 Answer

8/23/2021

It's working now. For other people who have the same problem. I have updated my deployment config from:

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernetes1-deployment
  labels:
    app: kubernetes1-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kubernetes1
  template:
    metadata:
      labels:
        app: kubernetes1
    spec:
      containers:
      - name: kubernetes1
        image: mycontainername.azurecr.io/kubernetes1:latest
        ports:
        - containerPort: 80

to:

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernetes1
spec:
  selector: # Define the wrapping strategy
    matchLabels: # Match all pods with the defined labels
      app: kubernetes1 # Labels follow the `name: value` template
  template: # This is the template of the pod inside the deployment
    metadata:
      labels:
        app: kubernetes1
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
        - image: mycontainername.azurecr.io/kubernetes1:latest
          name: kubernetes1
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 256Mi
          ports:
            - containerPort: 80
              name: http

I don't know exactly which line solved the problem. Feel free to comment it if you know which line the problem was.

-- 1408786user
Source: StackOverflow