how to get logs of deployment from kubernetes

社会主义新天地 提交于 2021-02-18 20:53:26

问题


I am create a influxdb deployment in kubernetes cluster(v1.15.2),this is my yaml file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: monitoring-influxdb
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        task: monitoring
        k8s-app: influxdb
    spec:
      containers:
      - name: influxdb
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2
        volumeMounts:
        - mountPath: /data
          name: influxdb-storage
      volumes:
      - name: influxdb-storage
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  labels:
    task: monitoring
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-influxdb
  name: monitoring-influxdb
  namespace: kube-system
spec:
  ports:
  - port: 8086
    targetPort: 8086
  selector:
    k8s-app: influxdb

and this is the pod status:

$ kubectl get deployment -n kube-system
NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
coredns                1/1     1            1           163d
kubernetes-dashboard   1/1     1            1           164d
monitoring-grafana     0/1     0            0           12m
monitoring-influxdb    0/1     0            0           11m

now I am waiting 30minites there is still no pod avaliabe,how to check the deployment log from command line? I could not access the kubernetes dashboard now.I am searching only command to get pod log,but now there is no pod avaliabe.I already tried to add label in node:

kubectl label nodes azshara-k8s03 k8s-app=influxdb

This is my deployment describe content:

$ kubectl describe deployments monitoring-influxdb -n kube-system
Name:                   monitoring-influxdb
Namespace:              kube-system
CreationTimestamp:      Wed, 04 Mar 2020 11:15:52 +0800
Labels:                 k8s-app=influxdb
                        task=monitoring
Annotations:            kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"extensions/v1beta1","kind":"Deployment","metadata":{"annotations":{},"name":"monitoring-influxdb","namespace":"kube-system"...
Selector:               k8s-app=influxdb,task=monitoring
Replicas:               1 desired | 0 updated | 0 total | 0 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:  k8s-app=influxdb
           task=monitoring
  Containers:
   influxdb:
    Image:        registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:
      /data from influxdb-storage (rw)
  Volumes:
   influxdb-storage:
    Type:        EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:   <unset>
OldReplicaSets:  <none>
NewReplicaSet:   <none>
Events:          <none>

this is another way to get logs:

$ kubectl -n kube-system logs -f deployment/monitoring-influxdb
error: timed out waiting for the condition

there is no output for this command:

kubectl logs --selector k8s-app=influxdb

there is all my pod in kube-system namespace:

~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/heapster/heapster-deployment ⌚ 11:57:40
$ kubectl get pods -n kube-system
NAME                                  READY   STATUS    RESTARTS   AGE
coredns-569fd64d84-5q5pj              1/1     Running   0          46h
kubernetes-dashboard-6466b68b-z6z78   1/1     Running   0          11h
traefik-ingress-controller-hx4xd      1/1     Running   0          11h

回答1:


You can try kubectl describe deploy monitoring-influxdb to get some high-level view of the deployment, maybe some information here.

For more detailed logs, first get the pods: kubectl get po Then, request the pod logs: kubectl logs <pod-name>




回答2:


kubectl logs deployment/<name-of-deployment> # logs of deployment
kubectl logs -f deployment/<name-of-deployment> # follow logs



回答3:


Adding references of two great tools that might help you view cluster logs:

  1. If you wish to view logs from your terminal without using a "heavy" 3rd party logging solution I would consider using K9S which is a great CLI tool that help you get control over your cluster.

  2. If you are not bound only to the CLI and still want run locally I would recommend on Lens.



来源:https://stackoverflow.com/questions/60518658/how-to-get-logs-of-deployment-from-kubernetes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!