Answers: <p>I think you haven't configured kubeconfig in root user.</p>
  <p><strong>The sudo command allows you to run programs with the security privileges of another user.</strong></p>
  <p>When you run <code>sudo kubectl</code> you're running <code>kubectl</code> with root user and most probably you might have not configured kubeconfig for root user.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-12-29T18:39:31.037Z
Answers: 2022-12-29T18:40:33.170Z
Answers: 2022-12-29T18:40:33.170Z
Answers: sujit patel
Answers: <p>This is only loosely related to your question, but if <code>kubectl get pods</code> gives:</p>
  <pre><code>No resources found in default namespace.
  </code></pre>
  <p>check <code>kubectl get namespaces</code> and then re-run the query with <code>kubectl get pods -n &lt;namespace&gt;</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-25T16:26:13.183Z
Answers: 2023-10-25T16:26:13.183Z
Answers: icc97
Body: <p>For example when I use <code>kubectl get pods</code> the response is:</p>
  <pre><code>No resources found in default namespace.
  </code></pre>
  <p>But when I use <code>sudo kubectl get pods</code> the result is:</p>
  <pre><code>E1211 12:01:15.409201   50965 memcache.go:238] couldn't get current server API group list: Get &quot;http://localhost:8080/api?timeout=32s&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.409569   50965 memcache.go:238] couldn't get current server API group list: Get &quot;http://localhost:8080/api?timeout=32s&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.411086   50965 memcache.go:238] couldn't get current server API group list: Get &quot;http://localhost:8080/api?timeout=32s&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.412633   50965 memcache.go:238] couldn't get current server API group list: Get &quot;http://localhost:8080/api?timeout=32s&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.414189   50965 memcache.go:238] couldn't get current server API group list: Get &quot;http://localhost:8080/api?timeout=32s&quot;: dial tcp 127.0.0.1:8080: connect: connection refused
  The connection to the server localhost:8080 was refused - did you specify the right host or port?
  </code></pre>
  <p>PS: From my previous knowledge I think when I use <code>kubectl</code> without <code>sudo</code>, it refers to <code>192.168.1.2:6443</code> but with the <code>sudo</code> word it is looking for <code>localhost:8080</code>. I don't know why?</p>
  
Tags: <kubernetes><kubectl><ports>
Title: Why do I get different responses either when I use `sudo` before `kubectl` or not?
UserDisplayName: best_of_man
ThreadText: # Why do I get different responses either when I use `sudo` before `kubectl` or not?
  
  (Asked by: username_0 on 2022-12-11)
  
  For example when I use `kubectl get pods` the response is:
  
  ```
  No resources found in default namespace.
  
  ```
  
  But when I use `sudo kubectl get pods` the result is:
  
  ```
  E1211 12:01:15.409201   50965 memcache.go:238] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.409569   50965 memcache.go:238] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.411086   50965 memcache.go:238] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.412633   50965 memcache.go:238] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
  E1211 12:01:15.414189   50965 memcache.go:238] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
  The connection to the server localhost:8080 was refused - did you specify the right host or port?
  
  ```
  
  PS: From my previous knowledge I think when I use `kubectl` without `sudo`, it refers to `192.168.1.2:6443` but with the `sudo` word it is looking for `localhost:8080`. I don't know why?
  
  **Tags:** kubernetes, kubectl, ports
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-12-29. Score: 2
  
  I think you haven't configured kubeconfig in root user.
  
  **The sudo command allows you to run programs with the security privileges of another user.**
  
  When you run `sudo kubectl` you're running `kubectl` with root user and most probably you might have not configured kubeconfig for root user.
  
  
  ---
  
  ### Answer by username_2 on 2023-10-25. Score: 0
  
  This is only loosely related to your question, but if `kubectl get pods` gives:
  
  ```
  No resources found in default namespace.
  
  ```
  
  check `kubectl get namespaces` and then re-run the query with `kubectl get pods -n <namespace>`
  
  
  ---
  
  