Shell 如何为PersistentVolumeClaim yaml文件单独筛选事件?
我们已经创建了pvc,它们处于待定状态。所以为了检查我们执行的状态Shell 如何为PersistentVolumeClaim yaml文件单独筛选事件?,shell,kubernetes,kubectl,Shell,Kubernetes,Kubectl,我们已经创建了pvc,它们处于待定状态。所以为了检查我们执行的状态 Kubectl describe -f <pvc.yml> Kubectl描述-f 它显示结果如下 Name: myproj-pvc-2020-09-29-04-02-1601377369-49419-1 Namespace: default StorageClass: myproj-storageclass-2020-09-29-04-02-1601377366 Status:
Kubectl describe -f <pvc.yml>
Kubectl描述-f
它显示结果如下
Name: myproj-pvc-2020-09-29-04-02-1601377369-49419-1
Namespace: default
StorageClass: myproj-storageclass-2020-09-29-04-02-1601377366
Status: Pending
Volume:
Labels: ansible=csitest-2020-09-29-04-02-1601377369-49419-1
pvcRef=csi-pvc-ansibles-1
Annotations: volume.beta.kubernetes.io/storage-provisioner: csi.myorg.com
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Mounted By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Provisioning 85s (x8 over 4m43s) csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee External provisioner is provisioning volume for claim "default/myproj-pvc-2020-09-29-04-02-1601377369-49419-1"
Warning ProvisioningFailed 74s (x8 over 4m33s) csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee failed to provision volume with StorageClass "myproj-storageclass-2020-09-29-04-02-1601377366": rpc error: code = Unavailable desc = Failed to get storage provider from secrets, Request failed with status code 401 and errors Error code (Unauthorized) and message (HTTP 401 Unauthorized.)
Normal ExternalProvisioning 6s (x20 over 4m43s) persistentvolume-controller waiting for a volume to be created, either by external provisioner "csi.myorg.com" or manually created by system administrat
名称:myproj-pvc-2020-09-29-04-02-1601377369-49419-1
名称空间:默认值
存储类别:myproj-StorageClass-2020-09-29-04-02-1601377366
状态:待定
卷:
标签:ansible=csitest-2020-09-29-04-02-1601377369-49419-1
pvcRef=csi-pvc-ansibles-1
注释:volume.beta.kubernetes.io/storage-provisioner:csi.myorg.com
终结器:[kubernetes.io/pvc保护]
容量:
访问模式:
VolumeMode:文件系统
安装人:
活动:
从消息中键入原因年龄
---- ------ ---- ---- -------
正常供应85s(x8/4m43s)csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee外部供应器是索赔“default/myproj-pvc-2020-09-29-04-02-1601377369-49419-1”的供应量
警告配置失败74s(x8超过4m33s)csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee未能使用存储类“myproj-StorageClass-2020-09-29-04-02-1601377366”配置卷:rpc错误:代码=不可用描述=无法从机密获取存储提供程序,请求失败,状态代码401、错误代码(未授权)和消息(HTTP 401未授权)
正常外部资源调配6s(x20/4m43s)persistentvolume控制器,等待外部资源调配器“csi.myorg.com”或系统管理员手动创建卷
我需要的是只过滤这个pvc.yaml的事件?如果我执行kubectl get-f pvc.yaml-o json
,它不会在json中显示错误事件
我可以做kubectl descripe-f | grep-A10事件:
,但不能保证只有10行总是出错
我还发现了这样一种方法kubectl get events--field selector involvedObject.kind=“PersistentVolumeClaim”
,但这将显示与所有pvc相关的所有事件。我需要得到Pvc.yml文件中提到的Pvc列表的事件
如何过滤pvc.yaml中所有pvc的事件?
kubectl get-f pvc.yaml-o json
确实有效,但我假设您的意思是kubectl get events-f pvc.yaml-o json
kubectl似乎不允许这种过滤。您可能希望在上打开功能请求
但与此同时,我想到了另一个选择:
kubectl get -f <pvc.yml> -ojson \
| jq ".items[] | .metadata.name" \
| xargs -I{} kubectl get events --field-selector involvedObject.kind="PersistentVolumeClaim",involvedObject.name={} --no-headers --ignore-not-found
kubectl get-f-ojson\
|jq“.items[]|.metadata.name”\
|xargs-I{}kubectl get events--字段选择器involvedObject.kind=“PersistentVolumeClaim”,involvedObject.name={}--没有头--找不到忽略
注意,您需要安装jq
。您还可以使用yq
,您不需要在转换为json时使用第一个技巧,但您需要稍微调整yq过滤器。我还假设您已经安装了kubectl,当然还有默认情况下在所有linux机器上都可以使用的xargs