<p>I have a k8s cluster, among other things running an nginx.
when I do <code>curl -v &lt;url&gt;</code> I get </p>

<pre><code>    HTTP/1.1 200 OK
&lt; Content-Type: text/html
&lt; Date: Fri, 24 Mar 2017 15:25:27 GMT
&lt; Server: nginx
&lt; Strict-Transport-Security: max-age=15724800; includeSubDomains; preload
&lt; Content-Length: 0
&lt; Connection: keep-alive
&lt;
* Curl_http_done: called premature == 0
* Connection #0 to host &lt;url&gt; left intact
</code></pre>

<p>however when I do <code>curl -v &lt;url&gt; -H 'Accept: application/json'</code> I get</p>

<pre><code>&lt; HTTP/1.1 200 OK
&lt; Content-Type: text/html
&lt; Date: Fri, 24 Mar 2017 15:26:10 GMT
&lt; Server: nginx
&lt; Strict-Transport-Security: max-age=15724800; includeSubDomains; preload
&lt; Content-Length: 0
&lt; Connection: keep-alive
&lt;
* Curl_http_done: called premature == 0
* Connection #0 to host &lt;url&gt; left intact
* Could not resolve host: application
* Closing connection 1
curl: (6) Could not resolve host: application
</code></pre>

<p>My task is to get the request to return a json not html.
To my understanding I have to create an ingress-controller and modify the ngnix.conf somehow, I've been trying for a few days now but can't get it right. Any kind of help would be most appreciated.</p>

<p>The following are of the yaml files I've been using:</p>

<p>configmap:</p>

<pre><code>apiVersion: v1
data:
  server-tokens: "false"
  proxy-body-size: "4110m"
  server-name-hash-bucket-size: "128"
kind: ConfigMap
metadata:
  name: nginx-load-balancer-conf
  labels:
    app: nginx-ingress-lb
</code></pre>

<p>daemonset:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ingress-lb
  labels:
    app: nginx-ingress-lb
spec:
  template:
    metadata:
      labels:
        name: nginx-ingress-lb
        app: nginx-ingress-lb

    spec:
      terminationGracePeriodSeconds: 60
      nodeSelector:
        NodeType: worker
      containers:
      - image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.1

        name: nginx-ingress-lb
        imagePullPolicy: Always
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        # use downward API
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
        - --configmap=$(POD_NAMESPACE)/nginx-load-balancer-conf
</code></pre>

<p>deployment:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment

metadata:
  name: default-http-backend
  labels:
    app: default-http-backend

spec:
  replicas: 2
  template:

    metadata:
      labels:
        app: default-http-backend

    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: default-http-backend
        # Any image is permissable as long as:
        # 1. It serves a 404 page at /
        # 2. It serves 200 on a /healthz endpoint
        image: gcr.io/google_containers/defaultbackend:1.2
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 100m
            memory: 20Mi
          requests:
            cpu: 100m
            memory: 20Mi
</code></pre>

<p>service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: default-http-backend
  labels:
    app: default-http-backend
spec:
  selector:
    app: default-http-backend
  ports:
  - port: 80
    targetPort: 8080
</code></pre>

<p>There are two things:</p>

<ul>
<li>Exposing your app</li>
<li>Making your app return json</li>
</ul>

<p>The ingess is only relevant to expose your app. And that is not the only option, you can use service (type Load balancer, for example) to achieve that too on most cloud providers. So, I'd keep it simple and not use ingress for now, until you solve the second problem.</p>

<p>As it has been explained, your curl has a syntax problem and that's why it shows <code>curl: (6) Could not resolve host: application</code>.</p>

<p>The other thing is fixing that won't make your app return json. And this is because you are only saying you accept json with that header. But if you want your app to return json, then you need to write it on your app. nginx can't guess how you want to map your HTML to json. There is much no other way than writting it, at least that I know of :-/</p>
