<p>I have an ASP.NET Core app that I want to configure with HTTPS in my local kubernetes clustur using minikube.</p>
<p>The deployment yaml file is:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube-volume
  labels:
    app: kube-volume-app
spec:
  replicas: 1
  selector: 
    matchLabels:
      component: web
  template:
    metadata: 
      labels:
        component: web
    spec:
      containers:
        - name: ckubevolume
          image: kubevolume
          imagePullPolicy: Never
          ports:
            - containerPort: 80
            - containerPort: 443
          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: Development
            - name: ASPNETCORE_URLS
              value: https://+:443;http://+:80
            - name: ASPNETCORE_HTTPS_PORT
              value: '443'
            - name: ASPNETCORE_Kestrel__Certificates__Default__Password
              value: mypass123
            - name: ASPNETCORE_Kestrel__Certificates__Default__Path
              value: /app/https/aspnetapp.pfx
          volumeMounts:
            - name: ssl
              mountPath: &quot;/app/https&quot;
      volumes:
        - name: ssl
          configMap:
            name: game-config
</code></pre>
<p>You can see i have added <strong>environment variables</strong> for https in yaml file.</p>
<p>I also created a service for this deployment. The yaml file of the service is:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: service-1
spec:
  type: NodePort
  selector:
    component: web
  ports:
    - name: http
      protocol: TCP
      port: 100
      targetPort: 80
    - name: https
      protocol: TCP
      port: 200
      targetPort: 443
</code></pre>
<p>But unfortunately the app is not opening by the service when I run the <strong>minikube service service-1</strong> command.</p>
<p>However when I remove the env variables for https then the app is opening by the service. These are the lines which when I remove the app opens:</p>
<pre><code>- name: ASPNETCORE_URLS
  value: https://+:443;http://+:80
- name: ASPNETCORE_HTTPS_PORT
  value: '443'
- name: ASPNETCORE_Kestrel__Certificates__Default__Password
  value: mypass123
- name: ASPNETCORE_Kestrel__Certificates__Default__Path
  value: /app/https/aspnetapp.pfx
</code></pre>
<p>I also confirmed with the shell that the certificate is present in the /app/https folder.</p>
<p>Whay I am doing wrong?</p>

<p>I think your approach does not fit well with the architecture of Kubernetes. A TLS certificate (for https) is coupled to a hostname.</p>
<p>I would recommend one of two different approaches:</p>
<ul>
<li>Expose your app with a Service of <code>type: LoadBalancer</code></li>
<li>Expose your app with an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress resource</a></li>
</ul>
<h2>Expose your app with a Service of type LoadBalancer</h2>
<p>This is typically called a Network LoadBalancer as it exposes your app for TCP or UDP directly.</p>
<p>See <a href="https://minikube.sigs.k8s.io/docs/handbook/accessing/#loadbalancer-access" rel="nofollow noreferrer">LoadBalancer access</a> in the Minikube documentation. But beware that your app get an external address from your LoadBalancer, and your TLS certificate probably has to match that.</p>
<h2>Expose your app with an Ingress resource</h2>
<p>This is the most common approach for Microservices in Kubernetes. In addition to your Service of <code>type: NodePort</code> you also need to create an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress resource</a> for your app.</p>
<p>The cluster needs an Ingress controller and the gateway will handle your TLS certificate, instead of your app.</p>
<p>See <a href="https://minikube.sigs.k8s.io/docs/tutorials/custom_cert_ingress/" rel="nofollow noreferrer">How to use custom TLS certificate with ingress addon</a> for how to configure both Ingress and TLS certificate in Minikube.</p>
<p>I would recommend to go this route.</p>
