'How to use kubectl proxy to verify a web server running in a pod?

I'm new in K8s and meet a problem. After I create a pod, I wanna use $ kubectl proxy to verify the webserver running in the deployed Pod. Here is the pod yaml file:

pod-example.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod-example
spec:
  containers:
  - name: nginx
    image: nginx:stable-alpine
    ports:
    - containerPort: 80

After I execute $ kubectl proxy, it shows like this:

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

But when I visit http://127.0.0.1:8001/api/v1/namespaces/dev/pods/pod-example/proxy/, it shows this:

kind    "Status"
apiVersion  "v1"
metadata    {}
status  "Failure"
message "pods \"pod-example\" not found"
reason  "NotFound"
details 
name    "pod-example"
kind    "pods"
code    404

The pod is running successfully, and the default "Welcome to nginx!" page should be visible... but I don't know what I did wrong. Please help me, thx!!!



Solution 1:[1]

  1. Get pod's namespace deployment:

    kubectl describe pod pod-example

  2. Try:

    http://127.0.0.1:8001/api/v1/namespaces/[PODS_NAMESPACE]/pods/pod-example/proxy/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pablo Atoche Seminario