0

I am trying to access the logs of a pod in a kubernetes cluster but get a 404 on sending the following rest request:

GET api/namespaces/myNamespace/pods/myPod/log

When I try to see the status of the pod I get the following:

"metadata": {
        "name": "podtest",
        "generateName": "podtest-",
        "namespace": "podtest01734160-58f9-4042-8f38-3e55d7d5beb3",
        "selfLink": "/api/v1/namespaces/podtest01734160-58f9-4042-8f38-3e55d7d5beb3/pods/podtest-rc-no-env-hc5rl",
        "uid": "dba5c41f-8307-11e5-96f2-005056976c6f",
        "resourceVersion": "3595515",
        "creationTimestamp": "2015-11-04T15:22:27Z",
        "labels": {
          "name": "kube-pod"
        },
        "annotations": {
          "kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"podtest01734160-58f9-4042-8f38-3e55d7d5beb3\",\"name\":\"podtest-rc-no-env\",\"uid\":\"dba55f97-8307-11e5-96f2-005056976c6f\",\"apiVersion\":\"v1\",\"resourceVersion\":\"3594964\"}}"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "podtest01734160-58f9-4042-8f38-3e55d7d5beb3",
            "image": "dockertest",
            "resources": {},
            "terminationMessagePath": "/dev/termination-log",
            "imagePullPolicy": "IfNotPresent"
          }
        ],
        "restartPolicy": "Always",
        "dnsPolicy": "ClusterFirst",
        "nodeName": "node-n2"
      },
      "status": {
        "phase": "Running",
        "conditions": [
          {
            "type": "Ready",
            "status": "True"
          }
        ],
        "hostIP": "172.29.225.12",
        "podIP": "10.20.96.20",
        "startTime": "2015-11-04T15:25:51Z",
        "containerStatuses": [
          {
            "name": "podtest01734160-58f9-4042-8f38-3e55d7d5beb3",
            "state": {
              "running": {
                "startedAt": "2015-11-04T15:28:43Z"
              }
            },
            "lastState": {},
            "ready": true,
            "restartCount": 0,
            "image": "dockertest",
            "imageID": "docker://62457b12fc411b13fcaa122a946aefcac0c66df05ce1158d8d618ebe3af95362",
            "containerID": "docker://baea3dc8cd7129704e205c76bf4ca57635659fec22774fcdcf197fb5c75ab433"
          }
        ]
      }
    },

Why can't I get to the logs?

Puck
  • 2,080
  • 4
  • 19
  • 30
user_mda
  • 18,148
  • 27
  • 82
  • 145

3 Answers3

0

This works from me /api/v1/namespaces/myNamespace/pods/myPod/log

Yours doesn't have the api version.

iocanel
  • 570
  • 2
  • 2
-1

try GET api/v1/namespaces/"podtest01734160-58f9-4042-8f38-3e55d7d5beb3"/pods/myPod/log

there are two points need to be aware: 1. in metadata it shows "namespace": "podtest01734160-58f9-4042-8f38-3e55d7d5beb3" but it is not myNamespace, 2. as the answer from iocanel, the api version is necessary, more info could be check here : kubernetes.io/v1.1/docs/api-reference/v1/operations.html

Zhi Yuan
  • 779
  • 1
  • 13
  • 20
  • there are two points need to be aware: 1. in metadata it shows "namespace": "podtest01734160-58f9-4042-8f38-3e55d7d5beb3" but it is not myNamespace, 2. as the answer from iocanel, the api version is necessary, more info could be check here : http://kubernetes.io/v1.1/docs/api-reference/v1/operations.html – Zhi Yuan Jan 19 '16 at 01:41
-1

I found these; When the pod status changes to Running you can use the kubectl logs command to view the output.

kubectl logs podname
https://github.com/kubernetes/kubernetes/blob/master/docs/getting-started-guides/logging.md
kubectl cluster-info
http://kubernetes.io/v1.0/docs/user-guide/accessing-the-cluster.html#accessing-the-api-from-a-pod How do I access the Kubernetes api from within a pod container?
Community
  • 1
  • 1
gelabel
  • 22
  • 1
  • 1
  • 8