Get YAML for deployed Kubernetes services?

前端 未结 12 1473
离开以前
离开以前 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:58

    If you need to view and edit the file use:

    kubectl edit service servicename

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

    The same issue is discussed at kubernetes GitHub issues page and the user "alahijani" made a bash script that exports all yaml and writes them to single files and folders.

    Since this question ranks well on Google and since I found that solution very good, I represent it here.

    Bash script exporting yaml to sub-folders:

    for n in $(kubectl get -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob)
    do
        mkdir -p $(dirname $n)
        kubectl get -o=yaml --export $n > $n.yaml
    done
    

    Another user "acondrat" made a script that do not use directories, which makes it easy to make a kubectl apply -f later.

    Bash script exporting yaml to current folder:

    for n in $(kubectl get -o=name pvc,configmap,ingress,service,secret,deployment,statefulset,hpa,job,cronjob | grep -v 'secret/default-token')
    do
        kubectl get -o=yaml --export $n > $(dirname $n)_$(basename $n).yaml
    done
    

    The last script does not include service account.

    0 讨论(0)
  • 2020-12-22 23:59
    • Like mentioned above "--export" is one option to get the manifest corresponding to the kubeernetes objects
    • But "--export" is considered to be buggy and there is a proposal to deprecate it
    • Currently the better option is to do "-o yaml" or "-o json" and remove the unnecessary fields
    • The main difference is "--export" is expected to remove the cluster specific settings (e.g. cluster service IP of a k8s service). But it is found to be inconsistent in this regard
    0 讨论(0)
  • 2020-12-23 00:00
    1. You can get the yaml files of the resources using this command

      kubectl -n <namespace> get <resource type> <resource Name> -o yaml

    2. To get the secret into your pod,

    use something like this

    env
    - valueFrom
        secretKeyRef:
          name: secret_name
          key: key_name
    

    or

    envFrom
    - secretRef:
        name: secret_name
    
     
    
    0 讨论(0)
  • 2020-12-23 00:02

    Use this command to get yaml format of your service

    kubectl get service servicename -n <namespace> -o yaml

    You can put it in some file also

    kubectl get service servicename -n <namespace> -o yaml > service.yaml

    0 讨论(0)
  • 2020-12-23 00:09

    I know it is too old to answer, but hopefully, someone will find it helpful.

    We can try below command to fetch a kind export from all namespace -

    kubectl get <kind> --all-namespaces --export -o yaml
    
    0 讨论(0)
提交回复
热议问题