如何从kubernetes获取部署日志

如何从kubernetes获取部署日志

本文介绍了如何从kubernetes获取部署日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在kubernetes集群(v1.15.2)中创建一个influxdb部署,这是我的yaml文件:

  apiVersion:extensions/v1beta1种类:部署元数据:名称:Monitoring-influxdb命名空间:kube-system规格:复制品:1模板:元数据:标签:任务:监控k8s-app:influxdb规格:容器:-名称:influxdb图片:registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2volumeMounts:-mountPath:/数据名称:influxdb-storage数量:-名称:influxdb-storageemptyDir:{}---apiVersion:v1种类:服务元数据:标签:任务:监控#用作集群附件(https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)#如果不将其用作插件,则应注释掉此行.kubernetes.io/cluster-service:true"kubernetes.io/名称:monitoring-influxdb名称:Monitoring-influxdb命名空间:kube-system规格:端口:-端口:8086targetPort:8086选择器:k8s-app:influxdb 

这是广告连播状态:

  $ kubectl获取部署-n kube-system姓名可用年龄coredns 1/1 1 1 163dkubernetes-dashboard 1/1 1 1 164d监控格拉芬娜0/1 0 0 12mMonitoring-Influxdb 0/1 0 0 11m 

现在我正在等待30分钟,仍然没有pod avaliabe,如何从命令行检查部署日志?我现在无法访问kubernetes仪表板.我仅搜索命令来获取pod日志,但是现在没有pod avaliabe.我已经尝试在node中添加标签:

  kubectl标签节点azshara-k8s03 k8s-app = influxdb 

这是我的部署描述内容:

  $ kubectl描述部署监视-influxdb -n kube-system名称:monitoring-influxdb命名空间:kube-systemCreationTimestamp:星期三,2020年3月4日11:15:52 +0800标签:k8s-app = influxdb任务=监控注释:kubectl.kubernetes.io/last-applied-configuration:{"apiVersion":"extensions/v1beta1","kind":"Deployment","metadata":{"annotations":{},"name":"monitoring-influxdb","namespace":"kube-system"...选择器:k8s-app = influxdb,任务=监控副本:1个所需|0更新|共0个|0可用|0不可用策略类型:RollingUpdateMinReadySeconds:0RollingUpdateStrategy:1个最大不可用,1个最大喘振Pod模板:标签:k8s-app = influxdb任务=监控容器:influxdb:图片:registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2端口:< none>主机端口:< none>环境:< none>坐骑:/influxdb-storage(rw)中的数据卷数:influxdb存储:类型:EmptyDir(共享容器寿命的临时目录)中等的:SizeLimit:< unset>OldReplicaSets:< none>NewReplicaSet:< none>事件:< none> 

这是获取日志的另一种方法:

  $ kubectl -n kube系统日志-f部署/监视-influxdb错误:等待条件超时 

此命令没有输出:

  kubectl日志--selector k8s-app = influxdb 

在kube-system命名空间中有我所有的pod:

 〜/Library/Mobile Documents/com〜apple〜CloudDocs/Document/k8s/work/heapster/heapster-deployment⌚11:57:40$ kubectl get pods -n kube-system名称就绪状态重启年龄coredns-569fd64d84-5q5pj 1/1运行中0 46hkubernetes-dashboard-6466b68b-z6z78 1/1正在运行0 11htraefik-ingress-controller-hx4xd 1/1正在运行0 11h 
解决方案

您可以尝试 kubectl describe deploy monitoring-influxdb 以获得部署的一些高级视图,也许这里有一些信息./p>

有关更详细的日志,请先获取吊舱: kubectl获取po 然后,请求Pod日志: kubectl日志< pod-name>

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
解决方案

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 poThen, request the pod logs: kubectl logs <pod-name>

这篇关于如何从kubernetes获取部署日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 02:24