我已经使用k8s Ansible模块创建了一些资源。现在,我想将资源导出到Kubernetes清单中(因此,我不再需要使用Ansible)。我首先导出了服务:
$ kubectl get svc myservice -o yaml --export > myservice.yaml
$ kubectl apply -f myservice.yaml
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
service/myservice configured
为什么我会收到警告?又为什么有service/myservice configured
而不是service/myservice unchanged
?有没有更好的方法来导出资源?
答案 0 :(得分:0)
您做对了,不必担心警告。
如果要删除它,则必须删除所有的generation
,selfLink
等键。
答案 1 :(得分:0)
是的,您做对了。 让我向您展示一个小技巧:
kubectl get svc myservice -o yaml --export | sed -e '/status:/d' -e '/creationTimestamp:/d' -e '/selfLink: [a-z0-9A-Z/]\+/d' -e '/resourceVersion: "[0-9]\+"/d' -e '/phase:/d' -e '/uid: [a-z0-9-]\+/d' > myservice.yaml
将在没有status, creationTimestamp, selfLink, resourceVersion, phase and uid
的情况下生成正确的Yaml文件。
答案 2 :(得分:0)
之所以收到警告,是因为您在先前使用dirname
创建的资源上使用了kubectl apply
。如果使用kubectl create
创建初始服务,则不会收到警告。
kubectl apply
而非configured
可能是由于某些元数据或生成的数据也包含在unchanged
的输出中。