{"id":11654,"date":"2025-10-19T14:56:11","date_gmt":"2025-10-19T14:56:11","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=11654"},"modified":"2025-10-19T14:56:11","modified_gmt":"2025-10-19T14:56:11","slug":"init-containers-in-kubernetes","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/init-containers-in-kubernetes\/","title":{"rendered":"Init containers in Kubernetes"},"content":{"rendered":"<p>Init containers can be used to perform initialization logic before the main containers run, these might include<\/p>\n<ul>\n<li>Waiting for a service to become available<\/li>\n<li>Run database migrations<\/li>\n<li>Copying files to a shared location<\/li>\n<li>Configuration set-up<\/li>\n<\/ul>\n<p>Init containers must run sequentially and complete successfully.<\/p>\n<pre class=\"brush: plain; highlight: [15]; title: ; notranslate\" title=\"\">\r\napiVersion: apps\/v1\r\nkind: Deployment\r\nmetadata:\r\n  name: my-app\r\nspec:\r\n  replicas: 1\r\n  selector:\r\n    matchLabels:\r\n      app: my-app\r\n  template:\r\n    metadata:\r\n      labels:\r\n        app: my-app\r\n    spec:\r\n      initContainers:\r\n      - name: wait-for-db\r\n        image: busybox\r\n        command: &#x5B;&#039;sh&#039;, &#039;-c&#039;, &#039;until nc -z db-service 5432; do echo waiting; sleep 2; done&#039;]\r\n      containers:\r\n      - name: app\r\n        image: my-app-image\r\n        ports:\r\n        - containerPort: 8080\r\n<\/pre>\n<p>This waits for a PostgreSQL service to become available before our application can start.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Init containers can be used to perform initialization logic before the main containers run, these might include Waiting for a service to become available Run database migrations Copying files to a shared location Configuration set-up Init containers must run sequentially and complete successfully. apiVersion: apps\/v1 kind: Deployment metadata: name: my-app spec: replicas: 1 selector: matchLabels: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[314],"tags":[],"class_list":["post-11654","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=11654"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11654\/revisions"}],"predecessor-version":[{"id":11656,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11654\/revisions\/11656"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=11654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=11654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=11654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}