{"id":8661,"date":"2022-03-07T14:32:44","date_gmt":"2022-03-07T19:32:44","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=8661"},"modified":"2023-09-19T18:17:43","modified_gmt":"2023-09-19T23:17:43","slug":"exporting-kubernetes-object-configs","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=8661","title":{"rendered":"Reverse engineering Kubernetes YAML&#8217;s"},"content":{"rendered":"\n<p>Ideally, the definitions for Kubernetes objects are all safely stored in your code repository &#8212; you can easily revert back to the previous, working iteration, you can see who changed what, and you&#8217;ve got a copy of it all available if super electromagnet man takes a stroll through the data center. Ideally. <\/p>\n\n\n\n<p>Here, in the real world, we took over management of a k8s implementation that&#8217;s been in service for about a year now. And, fortunately, the <em>production<\/em> YAMLs are all in the repo. The development system, on the other hand, <em>isn&#8217;t<\/em>. Logic dictates that the config would be similar, but it&#8217;s always good to check. <\/p>\n\n\n\n<p>I wrote a quick script to dump YAML files for all of the configmaps, cron jobs, deployments, horizontal pod autoscaling, jobs, persistent volumes, persistent volume claims, secrets, service accounts, services, and stateful sets.  <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\nnsbase=&quot;namespace\/&quot;\nfor ns in $(kubectl get namespaces -o=name)\ndo\n        ns=${ns#${nsbase}}\n        for n in $(kubectl get --namespace=$ns -o=name configmap,cronjob,deployment,hpa,job,pv,pvc,secret,serviceaccount,service,statefulset)\n        do\n            yamlfile=&quot;${ns}\/${n}.yaml&quot;\n            mkdir -p $(dirname ${ns}\/${n})\n            kubectl get --namespace=$ns -o=yaml $n &gt; $yamlfile\n        done\ndone\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Ideally, the definitions for Kubernetes objects are all safely stored in your code repository &#8212; you can easily revert back to the previous, working iteration, you can see who changed what, and you&#8217;ve got a copy of it all available if super electromagnet man takes a stroll through the data center. Ideally. Here, in the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1541],"tags":[1544,1546,1545,1542,615,1543],"class_list":["post-8661","post","type-post","status-publish","format-standard","hentry","category-kubernetes","tag-backup","tag-configuration-management","tag-export-config","tag-k8s","tag-kubernetes","tag-yaml"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8661"}],"version-history":[{"count":5,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8661\/revisions"}],"predecessor-version":[{"id":8681,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8661\/revisions\/8681"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}