{"id":1389,"date":"2019-08-27T11:43:48","date_gmt":"2019-08-27T08:43:48","guid":{"rendered":"https:\/\/artem.services\/?p=1387"},"modified":"2019-08-27T12:52:32","modified_gmt":"2019-08-27T09:52:32","slug":"1389","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1389&lang=en","title":{"rendered":"\u00a0Kubernetes &#8212; Save all manifest of an existing cluster"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-149 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png\" alt=\"\" width=\"844\" height=\"217\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png 844w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-300x77.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-768x197.png 768w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">To save all manifests, create a <strong>BASH<\/strong> script:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim k8s.sh\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">With the following contents:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\nDIR='k8s-manifests\/namespaces'\r\n\r\nmkdir -p $DIR\r\n\r\nfor NAMESPACE in $(kubectl get -o=name namespaces | cut -d '\/' -f2)\r\ndo\r\n\tfor TYPE in $(kubectl get -n $NAMESPACE -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob)\r\n\tdo\r\n\t    mkdir -p $(dirname $DIR\/$NAMESPACE\/$TYPE)\r\n\t    kubectl get -n $NAMESPACE -o=yaml $TYPE &gt; $DIR\/$NAMESPACE\/$TYPE.yaml\r\n\tdone\r\ndone\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Add the execution bit and run it:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nchmod +x k8s.sh\r\n.\/k8s.sh\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">After executing in the current directory in the folder &quot;<strong>k8s-manifests<\/strong>&quot; will be saved all manifests ordered by namespaces and types.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; To save all manifests, create a BASH script: &nbsp; With the following contents: &nbsp; Add the execution bit and run it: &nbsp; After executing in the current directory in the folder &quot;k8s-manifests&quot; will be saved all manifests ordered by namespaces and types.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[559],"tags":[549,1093,551],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1389"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1389"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1389\/revisions"}],"predecessor-version":[{"id":1391,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1389\/revisions\/1391"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}