我正在尝试访问kubernetes群集中的pod的日志,但在发送以下休息请求时获得404
:
获取api / namespaces / myNamespace / pods / myPod / log
当我尝试查看pod的状态时,我得到以下信息:
"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"
}
]
}
},
为什么我无法登录日志?
答案 0 :(得分:0)
这适用于我/ api / v1 / namespaces / myNamespace / pods / myPod / log
你的没有api版本。
答案 1 :(得分:-1)
试 GET api / v1 / namespaces /“podtest01734160-58f9-4042-8f38-3e55d7d5beb3”/ pods / myPod / log
有两点需要注意: 1.在元数据中它显示“命名空间”:“podtest01734160-58f9-4042-8f38-3e55d7d5beb3”,但它不是myNamespace, 2.作为iocanel的答案,api版本是必要的,更多信息 可以在这里查看: kubernetes.io/v1.1/docs/api-reference/v1/operations.html
答案 2 :(得分:-1)
我发现了这些; 当pod状态更改为Running时,您可以使用kubectl logs命令查看输出。
kubectl logs podnamehttps://github.com/kubernetes/kubernetes/blob/master/docs/getting-started-guides/logging.md
kubectl cluster-infohttp://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?