<p>So I have my own website that I am running and I want to migrate one of my services to my current cluster under a subdomain of my actual website and I'm having some trouble.</p>
<p>I have a website that I purchased off of NameCheap and I'm using Cloudfare for all the DNS stuff. So everything is setup correctly. What I can't seem to figure out what to do is getting my subdomain website to actually work.</p>
<p>I have tried to add a &quot;A&quot; and &quot;CNAME&quot; record and still can't get it to work.</p>
<p>I also tried to follow this site and got no luck. I have tried other stackoverflow links and links posted by cloudfare. But I couldn't get anything to work still:
<a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes" rel="nofollow noreferrer">https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes</a></p>
<p>My services are also running with no issues. My pods and deployments are also fine showing no errors and my website is already running on another link which I'm removing to save money. <a href="http://www.ecoders.ca" rel="nofollow noreferrer">www.ecoders.ca</a>. All I did to migrate over my service was add stuff to my ingress and re-deploy everything to my current cluster. On my current cluster I'm using NGINX.</p>
<p>LMK if more information is required.</p>
<p><strong>Ingress.yaml</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/from-to-www-redirect: &quot;true&quot;
#    nginx.ingress.kubernetes.io/rewrite-target: /
  name: ingress
spec:
  rules:
   - host: www.foo.com
     http:
       paths:
         - backend:
             serviceName: nk-webapp-service
             servicePort: 80
           path: /
         - backend:
             serviceName: stockapp-service
             servicePort: 80
           path: /stock
   - host: www.bar.foo.com &lt;----------- this does not work
     http:
       paths:
         - backend:
             serviceName: ecoders-webapi-service
             servicePort: 80
           path: /


</code></pre>
<p><strong>Cloudfare Setup</strong>
<a href="https://i.stack.imgur.com/yHWUz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yHWUz.png" alt="enter image description here" /></a></p>
<pre><code>CNAME -&gt; www -&gt; foo.com  
CNAME -&gt; bar -&gt; foo.com  
A -&gt; foo.com -&gt; IP ADDRESS  
</code></pre>
<p><strong>Service Setup</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecoders-webapi
spec:
  replicas: 1
  selector:
    matchLabels:
      name: ecoders-webapi
  template:
    metadata:
      labels:
        name: ecoders-webapi
    spec:
      containers:
        - name: webapi
          image: astronik/webservice:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080

</code></pre>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: ecoders-webapi-service
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      targetPort: 8080
  selector:
    name: ecoders-webapi

</code></pre>
<p><strong>UPDATED</strong></p>
<p><strong>Ingress.yaml</strong></p>
<pre><code>   - host: www.bar.foo.com
     http:
       paths:
         - backend:
             serviceName: ecoders-webapi-service
             servicePort: 80
           path: /
   - host: bar.foo.com
     http:
       paths:
         - backend:
             serviceName: ecoders-webapi-service
             servicePort: 80
           path: /
</code></pre>
<p>I added in a &quot;www&quot; link version as well, and now I'm getting this (before I was getting noting):</p>
<p><a href="https://i.stack.imgur.com/dG8yI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dG8yI.png" alt="enter image description here" /></a></p>
<p>Does this have something to do with TLS/SSL? Meaning my subdomain doesn't have a certificate?</p>
<p><strong>NEW UPDATE</strong></p>
<p>So under &quot;SSL/TLS&quot; on the Cloudfare dashboard. Once I turned it off I was able to access my subdomain with no problem. But now how do I get it to run on full? Does my kubernetes cluster require a certificate?</p>
<p><a href="https://i.stack.imgur.com/UHLle.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UHLle.png" alt="enter image description here" /></a></p>
<p><em><strong>SOLVED</strong></em></p>
<p>So it's all fixed up and it had to do with 2 little problems.</p>
<p><strong>Problem 1:</strong></p>
<p><a href="https://i.stack.imgur.com/cgOlE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cgOlE.png" alt="enter image description here" /></a></p>
<p>Essentially I need to change my DNS settings adding www. was adding another subdomain. I removed the 2 CNAMEs I created before and did this.</p>
<pre><code>A -&gt; bar -&gt; 10.0.0.0 
A -&gt; foo.com -&gt; 10.0.0.0 
</code></pre>
<p><strong>Problem 2:</strong></p>
<p>Needed to update my ingress to remove this line</p>
<pre><code>nginx.ingress.kubernetes.io/from-to-www-redirect: &quot;true&quot;
</code></pre>
<p><strong>Updated Ingress</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: ingress
spec:
  rules:
   - host: foo.com
     http:
       paths:
         - backend:
             serviceName: nk-webapp-service
             servicePort: 80
           path: /
         - backend:
             serviceName: stockapp-service
             servicePort: 80
           path: /stock
   - host: bar.foo.com
     http:
       paths:
         - backend:
             serviceName: ecoders-web-service
             servicePort: 80
           path: /
</code></pre>

Nikster
<p><em><strong>SOLVED</strong></em></p>
<p>So it's all fixed up and it had to do with 2 little problems. <a href="https://community.cloudflare.com/t/cloudflare-ssl-not-working-on-subdomains/3792" rel="nofollow noreferrer">Link Cloudfare Page</a></p>
<p><strong>Problem 1:</strong></p>
<p><a href="https://i.stack.imgur.com/cgOlE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cgOlE.png" alt="enter image description here" /></a></p>
<p>Essentially I need to change my DNS settings adding www. was adding another subdomain. I removed the 2 CNAMEs I created before and did this.</p>
<pre><code>A -&gt; bar -&gt; 10.0.0.0 
A -&gt; foo.com -&gt; 10.0.0.0 
</code></pre>
<p><strong>Problem 2:</strong></p>
<p>Needed to update my ingress to remove this line</p>
<pre><code>nginx.ingress.kubernetes.io/from-to-www-redirect: &quot;true&quot;
</code></pre>
<p><strong>Updated Ingress</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: ingress
spec:
  rules:
   - host: foo.com
     http:
       paths:
         - backend:
             serviceName: nk-webapp-service
             servicePort: 80
           path: /
         - backend:
             serviceName: stockapp-service
             servicePort: 80
           path: /stock
   - host: bar.foo.com
     http:
       paths:
         - backend:
             serviceName: ecoders-web-service
             servicePort: 80
           path: /
</code></pre>
