Can't access pod logs

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

  • Failed to config the https on the docker nginx container, always report time out
  • GitLab Ci with docker runner - Multiple Stages
  • Issue in “Accessing S3 bucket from ElasticBeanstalk using Docker Json file”
  • Jenkins in Docker: Unable to resolve VCS host
  • Fleet can't find data volume container
  • Volume changes not persistent after “docker-compose run” command (Django's collectstatic)
  • 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?

  • Mounting local directory into Docker container path that is not exposed as a VOLUME
  • CPP Rest SDK http_listener throws exception in nano server (in a Docker container)
  • Creating bash script from Dockerfile strips comments
  • docker-compose exec failed: executable file not found in $PATH
  • How debug Dockerfile which runs on one platform but not another
  • How to share host network bridge when using docker in docker
  • 3 Solutions collect form web for “Can't access pod logs”

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

    Yours doesn’t have the api version.

    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?

    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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.