<p dir="auto">There is no easy way to retrieve last termination resource / status for a pod except kubectl get pods -o option.</p>
<p dir="auto"><strong>Problem</strong><br>
When a container is killed and restarted because, for example, it hit memory limits, the <code class="notranslate">kubectl describe pod</code> output only shows an increasing <code class="notranslate">Restart Count</code> but no reason for why the container was killed:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[12:54:41] $ ./cluster/kubectl.sh describe pod simmemleak-hra99
Name:               simmemleak-hra99
Namespace:          default
Image(s):           saadali/simmemleak
Node:               kubernetes-minion-tf0f/10.240.216.66
Labels:             name=simmemleak
Status:             Running
Reason:             
Message:            
IP:             10.244.2.75
Replication Controllers:    simmemleak (1/1 replicas created)
Containers:
  simmemleak:
    Image:  saadali/simmemleak
    Limits:
      cpu:      100m
      memory:       50Mi
    State:      Running
      Started:      Tue, 07 Jul 2015 12:54:41 -0700
    Ready:      False
    Restart Count:  5
Conditions:
  Type      Status
  Ready     False 
Events:
  FirstSeen             LastSeen            Count   From                    SubobjectPath               Reason      Message
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {scheduler }                        scheduled   Successfully assigned simmemleak-hra99 to kubernetes-minion-tf0f
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   pulled      Pod container image &quot;gcr.io/google_containers/pause:0.8.0&quot; already present on machine
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   created     Created with docker id 6a41280f516d
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   started     Started with docker id 6a41280f516d
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    spec.containers{simmemleak}     created     Created with docker id 87348f12526a
..."><pre class="notranslate"><code class="notranslate">[12:54:41] $ ./cluster/kubectl.sh describe pod simmemleak-hra99
Name:               simmemleak-hra99
Namespace:          default
Image(s):           saadali/simmemleak
Node:               kubernetes-minion-tf0f/10.240.216.66
Labels:             name=simmemleak
Status:             Running
Reason:             
Message:            
IP:             10.244.2.75
Replication Controllers:    simmemleak (1/1 replicas created)
Containers:
  simmemleak:
    Image:  saadali/simmemleak
    Limits:
      cpu:      100m
      memory:       50Mi
    State:      Running
      Started:      Tue, 07 Jul 2015 12:54:41 -0700
    Ready:      False
    Restart Count:  5
Conditions:
  Type      Status
  Ready     False 
Events:
  FirstSeen             LastSeen            Count   From                    SubobjectPath               Reason      Message
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {scheduler }                        scheduled   Successfully assigned simmemleak-hra99 to kubernetes-minion-tf0f
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   pulled      Pod container image "gcr.io/google_containers/pause:0.8.0" already present on machine
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   created     Created with docker id 6a41280f516d
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    implicitly required container POD   started     Started with docker id 6a41280f516d
  Tue, 07 Jul 2015 12:53:51 -0700   Tue, 07 Jul 2015 12:53:51 -0700 1   {kubelet kubernetes-minion-tf0f}    spec.containers{simmemleak}     created     Created with docker id 87348f12526a
...
</code></pre></div>
<p dir="auto">We can find the reason by inspecting the pod object (<code class="notranslate">lastState</code> shows as <code class="notranslate">terminated</code> with <code class="notranslate">reason: OOM Killed</code>):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[12:55:13] clusterScaleDoc ~/go/src/github.com/GoogleCloudPlatform/kubernetes $ ./cluster/kubectl.sh get pods simmemleak-hra99 -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubernetes.io/created-by: '{&quot;kind&quot;:&quot;SerializedReference&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;reference&quot;:{&quot;kind&quot;:&quot;ReplicationController&quot;,&quot;namespace&quot;:&quot;default&quot;,&quot;name&quot;:&quot;simmemleak&quot;,&quot;uid&quot;:&quot;e3eca54a-24e1-11e5-b668-42010af06b29&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;resourceVersion&quot;:&quot;409344&quot;}}'
  creationTimestamp: 2015-07-07T19:53:51Z
  generateName: simmemleak-
  labels:
    name: simmemleak
  name: simmemleak-hra99
  namespace: default
  resourceVersion: &quot;409448&quot;
  selfLink: /api/v1/namespaces/default/pods/simmemleak-hra99
  uid: e3f09bb6-24e1-11e5-b668-42010af06b29
spec:
  containers:
  - image: saadali/simmemleak
    imagePullPolicy: IfNotPresent
    name: simmemleak
    resources:
      limits:
        cpu: 100m
        memory: 50Mi
    terminationMessagePath: /dev/termination-log
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-dghxl
      readOnly: true
  dnsPolicy: ClusterFirst
  nodeName: kubernetes-minion-tf0f
  restartPolicy: Always
  serviceAccountName: default
  volumes:
  - name: default-token-dghxl
    secret:
      secretName: default-token-dghxl
status:
  conditions:
  - status: &quot;False&quot;
    type: Ready
  containerStatuses:
  - containerID: docker://cabb33b37eed421ab7fb4ee35e15ae58f58b39a567c0702877460763d891c2d5
    image: saadali/simmemleak
    imageID: docker://8f1003e60b90bffb090ee08da80da2646ff5effbd9ae735797bbe408701665d1
    lastState:
      terminated:
        containerID: docker://12d22d35413aef641369d5fc9cf5f367a26017dc2d3c6817ed6d4fdcf8d2120a
        exitCode: 137
        finishedAt: 2015-07-07T19:55:02Z
        reason: OOM Killed
        startedAt: 2015-07-07T19:55:02Z
    name: simmemleak
    ready: false
    restartCount: 8
    state:
      running:
        startedAt: 2015-07-07T19:55:12Z
  hostIP: 10.240.216.66
  phase: Running
  podIP: 10.244.2.75
  startTime: 2015-07-07T19:53:51Z"><pre class="notranslate"><code class="notranslate">[12:55:13] clusterScaleDoc ~/go/src/github.com/GoogleCloudPlatform/kubernetes $ ./cluster/kubectl.sh get pods simmemleak-hra99 -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubernetes.io/created-by: '{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationController","namespace":"default","name":"simmemleak","uid":"e3eca54a-24e1-11e5-b668-42010af06b29","apiVersion":"v1","resourceVersion":"409344"}}'
  creationTimestamp: 2015-07-07T19:53:51Z
  generateName: simmemleak-
  labels:
    name: simmemleak
  name: simmemleak-hra99
  namespace: default
  resourceVersion: "409448"
  selfLink: /api/v1/namespaces/default/pods/simmemleak-hra99
  uid: e3f09bb6-24e1-11e5-b668-42010af06b29
spec:
  containers:
  - image: saadali/simmemleak
    imagePullPolicy: IfNotPresent
    name: simmemleak
    resources:
      limits:
        cpu: 100m
        memory: 50Mi
    terminationMessagePath: /dev/termination-log
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-dghxl
      readOnly: true
  dnsPolicy: ClusterFirst
  nodeName: kubernetes-minion-tf0f
  restartPolicy: Always
  serviceAccountName: default
  volumes:
  - name: default-token-dghxl
    secret:
      secretName: default-token-dghxl
status:
  conditions:
  - status: "False"
    type: Ready
  containerStatuses:
  - containerID: docker://cabb33b37eed421ab7fb4ee35e15ae58f58b39a567c0702877460763d891c2d5
    image: saadali/simmemleak
    imageID: docker://8f1003e60b90bffb090ee08da80da2646ff5effbd9ae735797bbe408701665d1
    lastState:
      terminated:
        containerID: docker://12d22d35413aef641369d5fc9cf5f367a26017dc2d3c6817ed6d4fdcf8d2120a
        exitCode: 137
        finishedAt: 2015-07-07T19:55:02Z
        reason: OOM Killed
        startedAt: 2015-07-07T19:55:02Z
    name: simmemleak
    ready: false
    restartCount: 8
    state:
      running:
        startedAt: 2015-07-07T19:55:12Z
  hostIP: 10.240.216.66
  phase: Running
  podIP: 10.244.2.75
  startTime: 2015-07-07T19:53:51Z
</code></pre></div>
<p dir="auto"><strong>Suggested Solution</strong><br>
Modify <code class="notranslate">kubectl describe pod</code> to print <code class="notranslate">lastState</code> termination reason, if available.</p>