我试图将我的应用程序部署到运行在谷歌容器中的Kubernetes 引擎。

该应用程序可以在https://github.com/Industrial/docker-znc上找到。

Dockerfile内置于谷歌容器注册表上的映像中。

我已经通过+按钮在Kubernetes中部署了应用程序。我没有YAML 对于这个。

我已经在Kubernetes中插入了一个Secret,用于应用程序所需的PEM文件。

如何获得由创建的部署、服务和Pod的YAML Kubernetes通过填写表格? 我如何把秘密进入我的豆荚使用?


当前回答

我知道这个问题太老了,无法回答,但希望有人会觉得它有帮助。

我们可以尝试下面的命令从所有命名空间-中获取一个kind导出

kubectl get <kind> --all-namespaces --export -o yaml

其他回答

如果你需要“干净”的导出,删除Kubernetes添加的注释,有一个开源项目可以通过连接kubectl get - https://github.com/itaysk/kubectl-neat的输出来做到这一点。

它删除时间戳元数据,等等。

kubectl get pod mypod -o yaml | kubectl neat

kubectl get pod mypod -oyaml | kubectl neat -o json

您可以尝试使用kube-dump bash脚本

使用这个实用工具,您可以将Kubernetes集群资源保存为纯yaml清单,无需不必要的元数据。

GitHub库 回顾博客页面中的实用程序

如果您有读访问权限,我们可以通过命令行从Kubernetes集群中获取与任何类型相关的内容。

kubectl get <kind> <kindname> -n <namespace> -o <yaml or json>

例如,如果希望从名称空间导出部署,请执行以下命令-

kubectl get deploy mydeploy -n mynamespace -o yaml > mydeploy.yaml

kubectl get deploy mydeploy -n mynamespace -o json > mydeploy.json

要获取kubernetes上当前运行部署的YAML,可以运行这个命令:

kubectl get deployment <deployment_name> -o yaml

要生成YAML用于部署,可以运行命令式命令。

kubectl create deployment <deployment_name>--image=<image_name> -o yaml

要生成并导出部署,可以运行imperative命令。

 kubectl create deployment <deployment_name>--image=<image_name> --dry-run=client -o yaml > example.yaml

关于秘密的第二个问题,这来自k8s的文档。更多信息请参见https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets。

Create a secret or use an existing one. Multiple pods can reference the same secret. Modify your Pod definition to add a volume under spec.volumes[]. Name the volume anything, and have a spec.volumes[].secret.secretName field equal to the name of the secret object. Add a spec.containers[].volumeMounts[] to each container that needs the secret. Specify spec.containers[].volumeMounts[].readOnly = true and spec.containers[].volumeMounts[].mountPath to an unused directory name where you would like the secrets to appear. Modify your image and/or command line so that the program looks for files in that directory. Each key in the secret data map becomes the filename under mountPath.

我用过这个,它工作得很好。