Get YAML for deployed Kubernetes services?

2020-05-13 20:16发布

I am trying to deploy my app to Kubernetes running in Google Container Engine.

The app can be found at: https://github.com/Industrial/docker-znc.

The Dockerfile is built into an image on Google Container Registry.

I have deployed the app in Kubernetes via the + button. I don't have the YAML for this.

I have inserted a Secret in Kubernetes for the PEM file required by the app.

  1. How do I get the YAML for the Deployment, Service and Pod created by Kubernetes by filling in the form?
  2. How do I get the Secret into my Pod for usage?

9条回答
小情绪 Triste *
2楼-- · 2020-05-13 21:11

Syntax for downloading yaml's from kubernetes

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

Create yaml file from running pod:

  1. kubectl get po -n nginx nginx-deployment-755cfc7dcf-5s7j8 -o yaml > podDetail.yaml

Create replicaset yaml file from running pod:

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

Create deployement yaml file from running pod:

  1. kubectl get deploy -n nginx -o yaml > latestDeployement.yaml
查看更多
做自己的国王
3楼-- · 2020-05-13 21:11

If you need to view and edit the file use:

kubectl edit service servicename

查看更多
Juvenile、少年°
4楼-- · 2020-05-13 21:17

for the 2nd question regarding the secret, this is from the k8s documentation. see https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets for more info.

  1. Create a secret or use an existing one. Multiple pods can reference the same secret.
  2. 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.
  3. 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.
  4. 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.

I have used this and it works fine.

查看更多
登录 后发表回答