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

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

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

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

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

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


当前回答

从kubernetes下载yaml的语法

kubectl get [resource type] -n [namespace] [resource Name] -o yaml > [New file name]

从运行的pod创建yaml文件:

kubectl得到po -n nginx nginxdeploymentt55cfc7dcf -5s7j8 -o yaml > podDetail.yaml

从运行的pod中创建副本yaml文件:

kubectl get rs -n nginx -o yaml > latestReplicaSet.yaml

从运行的pod创建部署yaml文件:

kubectl get deploy -n nginx -o yaml > latestdeployment .yaml

其他回答

现在——export已弃用,要以'原始'格式从资源中获得输出(刚刚清理了,没有任何关于当前对象状态的信息(在这种情况下不必要的元数据)),您可以使用yq v4.x执行以下操作:

kubectl get <resource> -n <namespace> <resource-name> -o yaml \
  | yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .metadata.managedFields)' -

下面的代码将一次性提取所有K8s定义,并将它们放在当前文件夹下面的单独文件夹中。

for OBJ in $(kubectl api-resources --verbs=list --namespaced -o name)
do
   for DEF in $(kubectl get --show-kind --ignore-not-found $OBJ -o name)
   do
      mkdir -p $(dirname $DEF)
      kubectl get $DEF -o yaml \
      | yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .metadata.managedFields)' - > $DEF.yaml 
   done
done

所有的服务

kubectl get service --all-namespaces -o yaml  > all-service.yaml

所有部署

kubectl get deploy --all-namespaces -o yaml  > all-deployment.yaml

如果您需要查看和编辑文件,请使用:

kubectl编辑服务

关于秘密的第二个问题,这来自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.

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