<p>I deployed a REST API application YAML in Kubernetes and I tried to access that API from another namespace. But it shows error. How to access the rest API from a different namespace. Below is my deployment YAML</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: configuration
  labels:
    app: configuration
  namespace: restapi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: configuration
  template:
    metadata:
      labels:
        app: configuration
    spec:
      containers:
      - name: configuration
        image: global.azurecr.io/config:1
        env:
        - name: AzureFunctionsJobHost__functions__0
          value: configuration
        envFrom:
        - secretRef:
            name: configuration
      imagePullSecrets:
      - name: pull
</code></pre>
<p>URL for API calls from other namespace is
<strong>&quot;http://configuration.restapi:80/api/configuration&quot;</strong>
I tried with <strong>.restapi</strong> in my url but its not working.
I can call rest API in the same namespace.</p>

Arun Thomas
<p>You can always do a simple test to check if you can reach from different namespace.</p>
<p>Lets say you don't have a service.</p>
<p>Then you can reach the pod directly using the ip like below.</p>
<pre><code>kubectl run dnstest --image=busybox:1.28 --restart=Never --rm -ti -- nslookup 10-36-0-2.default.pod
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      10-36-0-2.default.pod
Address 1: 10.36.0.2
pod &quot;dnstest&quot; deleted

</code></pre>
<p>And if you expose the service like below</p>
<pre><code>kubectl expose deployment configuration --port 80 -n restapi
</code></pre>
<p>Then the result of the test is below.</p>
<pre><code>kubectl run dnstest --image=busybox:1.28 --restart=Never --rm -ti -- nslookup configuration.restapi
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      configuration.restapi
Address 1: 10.105.110.174 configuration.restapi.svc.cluster.local
pod &quot;dnstest&quot; deleted
</code></pre>
<p>You can use configuration.restapi or configuration.restapi.svc or configuration.restapi.svc.cluster.local in an standard kubernetes environment.</p>
