{"id":4075,"date":"2025-02-21T14:52:28","date_gmt":"2025-02-21T14:52:28","guid":{"rendered":"https:\/\/code2deploy.com\/blog\/?p=4075"},"modified":"2025-02-21T14:52:28","modified_gmt":"2025-02-21T14:52:28","slug":"deploying-without-downtime-in-kubernetes","status":"publish","type":"post","link":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/","title":{"rendered":"Deploying Without Downtime in Kubernetes"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ensuring zero downtime during deployment updates is a crucial requirement for modern applications. Kubernetes provides a <strong>RollingUpdate<\/strong> strategy that allows you to update applications seamlessly without disrupting users.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Rolling Updates?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>rolling update<\/strong> gradually replaces old pods with new ones, ensuring that your application remains available during deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Key features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Readiness Probes<\/strong>: Prevents traffic from reaching new pods until they are fully ready.<\/li>\n\n\n\n<li><strong>Liveness Probes<\/strong>: Detects and restarts unresponsive containers to maintain application health.<\/li>\n\n\n\n<li><strong>MaxUnavailable: 1<\/strong>: Ensures at least one pod is always running.<\/li>\n\n\n\n<li><strong>MaxSurge: 1<\/strong>: Allows one extra pod to be created during the rollout.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Example: Kubernetes Deployment with Rolling Updates, Readiness, and Liveness Probes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a detailed example of how to deploy an application using a rolling update strategy with both <strong>readiness<\/strong> and <strong>liveness<\/strong> probes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: my-app\nspec:\n  replicas: 3  # Ensuring high availability\n  strategy:\n    type: RollingUpdate\n    rollingUpdate:\n      maxUnavailable: 1  # At most, 1 pod is unavailable at a time\n      maxSurge: 1  # Allows 1 extra pod to be created\n  selector:\n    matchLabels:\n      app: my-app\n  template:\n    metadata:\n      labels:\n        app: my-app\n    spec:\n      containers:\n      - name: my-app-container\n        image: my-app:v2  # New version\n        ports:\n        - containerPort: 80\n        readinessProbe:\n          httpGet:\n            path: \/health\n            port: 80\n          initialDelaySeconds: 3\n          periodSeconds: 5\n        livenessProbe:\n          httpGet:\n            path: \/health\n            port: 80\n          initialDelaySeconds: 5\n          periodSeconds: 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation of Configuration:<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Replicas:<\/strong> At least 3 pods are maintained to ensure availability.<\/li>\n\n\n\n<li><strong>Rolling Update Strategy:<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>maxUnavailable: 1<\/code> ensures at least one pod is always running.<\/li>\n\n\n\n<li><code>maxSurge: 1<\/code> allows Kubernetes to create a new pod before removing an old one.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Readiness Probe:<\/strong> Prevents traffic from reaching pods until they pass health checks.<\/li>\n\n\n\n<li><strong>Liveness Probe:<\/strong> Ensures that unresponsive containers are restarted automatically.<\/li>\n\n\n\n<li><strong>Image Update (<\/strong><code><strong>my-app:v2<\/strong><\/code><strong>)<\/strong>: This defines the new version being deployed.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Use Case<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>E-commerce Application Deployment<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Consider an online shopping platform that cannot afford downtime, especially during sales events. Using the above strategy:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The backend services can be updated without affecting customer transactions.<\/li>\n\n\n\n<li>Readiness probes ensure users only interact with fully initialized pods.<\/li>\n\n\n\n<li>Liveness probes restart unresponsive containers, preventing failures.<\/li>\n\n\n\n<li>Users experience zero disruption while the new version is deployed.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Zero Downtime Deployment<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Monitor Deployments:<\/strong> Use <code>kubectl rollout status deployment my-app<\/code> to track updates.<\/li>\n\n\n\n<li><strong>Rollback on Failure:<\/strong> Use <code>kubectl rollout undo deployment my-app<\/code> to revert if issues arise.<\/li>\n\n\n\n<li><strong>Use Canary Deployments:<\/strong> Gradually route traffic to the new version to test performance before full rollout.<\/li>\n\n\n\n<li><strong>Test Probes Regularly:<\/strong> Ensure the liveness and readiness probes correctly reflect application health.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A rolling update strategy, combined with readiness and liveness probes, ensures that deployments occur smoothly without downtime. By leveraging these techniques, you can deliver updates with confidence while keeping services online at all times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Would you like to explore blue-green deployments or canary releases for even more controlled rollouts? Let us know in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Ensuring zero downtime during deployment updates is a crucial requirement for modern applications. Kubernetes provides a RollingUpdate strategy that allows you to update applications seamlessly without disrupting users. Why Use Rolling Updates? A rolling update gradually replaces old pods with new ones, ensuring that your application remains available during deployment. Key features: Example: Kubernetes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,216],"tags":[11,532,531,533],"class_list":["post-4075","post","type-post","status-publish","format-standard","hentry","category-kubernetes","category-kubernetes-basic","tag-kubernetes-deployment","tag-liveness-probes","tag-readiness-probes","tag-rollingupdate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Deploying Without Downtime in Kubernetes - code2deploy.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deploying Without Downtime in Kubernetes - code2deploy.com\" \/>\n<meta property=\"og:description\" content=\"Introduction Ensuring zero downtime during deployment updates is a crucial requirement for modern applications. Kubernetes provides a RollingUpdate strategy that allows you to update applications seamlessly without disrupting users. Why Use Rolling Updates? A rolling update gradually replaces old pods with new ones, ensuring that your application remains available during deployment. Key features: Example: Kubernetes [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/\" \/>\n<meta property=\"og:site_name\" content=\"code2deploy.com\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-21T14:52:28+00:00\" \/>\n<meta name=\"author\" content=\"enam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"enam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/\"},\"author\":{\"name\":\"enam\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"headline\":\"Deploying Without Downtime in Kubernetes\",\"datePublished\":\"2025-02-21T14:52:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/\"},\"wordCount\":365,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"keywords\":[\"Kubernetes deployment\",\"Liveness Probes\",\"Readiness Probes\",\"RollingUpdate\"],\"articleSection\":[\"Kubernetes\",\"Kubernetes Basic\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/\",\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/\",\"name\":\"Deploying Without Downtime in Kubernetes - code2deploy.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#website\"},\"datePublished\":\"2025-02-21T14:52:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/deploying-without-downtime-in-kubernetes\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deploying Without Downtime in Kubernetes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/\",\"name\":\"code2deploy.com\\\/blog\",\"description\":\"TechOps\",\"publisher\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\",\"name\":\"enam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"caption\":\"enam\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/code2deploy.com\\\/blog\"],\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/author\\\/enam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deploying Without Downtime in Kubernetes - code2deploy.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/","og_locale":"en_US","og_type":"article","og_title":"Deploying Without Downtime in Kubernetes - code2deploy.com","og_description":"Introduction Ensuring zero downtime during deployment updates is a crucial requirement for modern applications. Kubernetes provides a RollingUpdate strategy that allows you to update applications seamlessly without disrupting users. Why Use Rolling Updates? A rolling update gradually replaces old pods with new ones, ensuring that your application remains available during deployment. Key features: Example: Kubernetes [&hellip;]","og_url":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/","og_site_name":"code2deploy.com","article_published_time":"2025-02-21T14:52:28+00:00","author":"enam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"enam","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/#article","isPartOf":{"@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/"},"author":{"name":"enam","@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"headline":"Deploying Without Downtime in Kubernetes","datePublished":"2025-02-21T14:52:28+00:00","mainEntityOfPage":{"@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/"},"wordCount":365,"commentCount":0,"publisher":{"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"keywords":["Kubernetes deployment","Liveness Probes","Readiness Probes","RollingUpdate"],"articleSection":["Kubernetes","Kubernetes Basic"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/","url":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/","name":"Deploying Without Downtime in Kubernetes - code2deploy.com","isPartOf":{"@id":"https:\/\/code2deploy.com\/blog\/#website"},"datePublished":"2025-02-21T14:52:28+00:00","breadcrumb":{"@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/code2deploy.com\/blog\/deploying-without-downtime-in-kubernetes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code2deploy.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Deploying Without Downtime in Kubernetes"}]},{"@type":"WebSite","@id":"https:\/\/code2deploy.com\/blog\/#website","url":"https:\/\/code2deploy.com\/blog\/","name":"code2deploy.com\/blog","description":"TechOps","publisher":{"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code2deploy.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b","name":"enam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","caption":"enam"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g"},"sameAs":["https:\/\/code2deploy.com\/blog"],"url":"https:\/\/code2deploy.com\/blog\/author\/enam\/"}]}},"_links":{"self":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/comments?post=4075"}],"version-history":[{"count":1,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4075\/revisions"}],"predecessor-version":[{"id":4076,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4075\/revisions\/4076"}],"wp:attachment":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/media?parent=4075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/categories?post=4075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/tags?post=4075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}