Get YAML for deployed Kubernetes services?

前端 未结 12 1483
离开以前
离开以前 2020-12-22 23:28

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.

相关标签:
12条回答
  • 2020-12-22 23:42

    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
    0 讨论(0)
  • 2020-12-22 23:46

    To get the yaml for a deployment (service, pod, secret, etc):

    kubectl get deploy deploymentname -o yaml --export
    
    0 讨论(0)
  • 2020-12-22 23:46

    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.

    0 讨论(0)
  • 2020-12-22 23:48
    kubectl -n <namespace> get <resource type> <resource Name> -o yaml 
    

    With the command above, any resource defined in Kubernetes can be exported in YAML format.

    0 讨论(0)
  • 2020-12-22 23:52

    How do I get the YAML for the Deployment, Service and Pod created by Kubernetes by filling in the form?

    kubectl get deployment,service,pod yourapp -o yaml --export
    

    Answering @Sinaesthetic question:

    any idea how to do it for the full cluster (all deployments)?

    kubectl get deploy --all-namespaces -o yaml --export
    

    The problem with this method is that export doesn't include the namespace. So if you want to export many resources at the same time, I recommend doing it per namespace:

    kubectl get deploy,sts,svc,configmap,secret -n default -o yaml --export > default.yaml
    

    Unfortunately kubernetes still doesn't support a true get all command, so you need to list manually the type of resources you want to export. You can get a list of resource types with

    kubectl api-resources
    
    0 讨论(0)
  • 2020-12-22 23:53

    Is only minor difference from @Janos Lenart's answer!

    kubectl get deploy deploymentname -o yaml > outputFile.yaml will do

    0 讨论(0)
提交回复
热议问题