How to access Azure Dev Space Deployment only through a specific port?

1/8/2020

I have a ASP.NET Core WebApi Project deployed on Azure Dev Spaces which I access with the following URL (redacted):

http://xxxxxxxxx-devspace-dev.xxxxxxxxxxxxxxxcustomerwebapi.xxxxxxxx.sea.azds.io/swagger/index.html

I want to limit the access of the URL so that it can be only be accessed with a specified port. Example port 7501:

http://xxxxxxxxx-devspace-dev.xxxxxxxxxxxxxxxcustomerwebapi.xxxxxxxx.sea.azds.io:7501/swagger/index.html

I use azds up to deploy the project to Dev Space.

I have the following Docker.develop file which is used to deploy on Dev Spaces:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_URLS=http://+:80
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
EXPOSE 80

WORKDIR /src
COPY ["nuget.config", "./"]
COPY ["xxxxxxxxx.Customer.WebApi.csproj", "./"]
RUN dotnet restore "xxxxxxxxx.Customer.WebApi.csproj"
COPY . .
RUN dotnet build --no-restore -c $BUILD_CONFIGURATION

RUN echo "exec dotnet run --no-build --no-launch-profile -c $BUILD_CONFIGURATION -- \"\$@\"" > /entrypoint.sh

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

My charts' values.yaml file contains the following piece of script:

service:
  type: ClusterIP
  port: 80

And charts' templates' deployment.yaml has the following piece:

spec:
  revisionHistoryLimit: 0
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "xxxxxxxxxcustomerwebapi.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "xxxxxxxxxcustomerwebapi.name" . }}
        draft: {{ .Values.draft | default "draft-app" }}
        release: {{ .Release.Name }}
      annotations:
        buildID: {{ .Values.buildID | default "" | quote }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          {{- if .Values.probes.enabled }}
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          {{- end }}
          env:
            {{- $root := . }}
            {{- range $ref, $values := .Values.secrets }}
            {{- range $key, $value := $values }}
            - name: {{ $ref }}_{{ $key }}
              valueFrom:
                secretKeyRef:
                  name: {{ template "xxxxxxxxxcustomerwebapi.fullname" $root }}-{{ $ref | lower }}
                  key: {{ $key }}
            {{- end }}
            {{- end }}

But, changing the ports from these files only results in BadGateway and the URL with port number 7501 doesn't work.

Can somebody please guide me through how do I access URL only through a specified port number?

-- Achal Sharma
asp.net-core-webapi
azure-dev-spaces
docker
kubernetes
visual-studio-code

0 Answers