在尝试使用apiVersion和种类之前,如何检查和/或等待它们存在?
示例:
使用cilium安装cilium和网络策略
kubectl apply -f cilium.yaml
kubectl apply -f policy.yaml # fails if run just after installing cilium, since cilium.io/v2 and CiliumNetworkPolicy doesn't exist yet
policy.yaml
apiVersion: cilium.io/v2
description: example policy
kind: CiliumNetworkPolicy
...
编辑:(由以下脚本解决)
#! /bin/bash
function check_api {
local try=0
local retries=30
until (kubectl "api-$1s" | grep -P "\b$2\b") &>/dev/null; do
(( ++try > retries )) && exit 1
echo "$2 not found. Retry $try/$retries"
sleep 3
done
}
kubectl apply -f cilium.yaml
check_api version cilium.io/v2
check_api resource CiliumNetworkPolicy
kubectl apply -f policy.yaml
答案 0 :(得分:2)
您可以使用以下命令检查受支持的版本和种类,即检查您要与之通信的API服务器:
$ kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
...
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
还有kubectl api-resources
为您提供了有关种类,简称以及资源是否命名空间的表格概览。