Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Init Container Build Pattern: Knative build with plain old Kubernetes deployment

April 1, 2019
Kamesh Sampath
Related topics:
JavaContainersKubernetesQuarkus

Share:

    With Kubernetes evolving at supersonic speed and seeing a lot of adoption in the enterprise world, the developer community is now looking for solutions to common Kubernetes problems, such as patterns. In this article, I will explore a new Kubernetes pattern using Init Containers.

    Let's start with the use case that gave birth to this problem: Quarkus—Supersonic and Subatomic Java—has excited the Java developer community with its amazing speed and all new native build artifact for Java applications. As one of those excited developers, I want to quickly build and deploy a Quarkus application on to Kubernetes.

    Before we deploy the Quarkus application on Kubernetes, however, we need to solve the following problems:

    • How to build a container image natively on Kubernetes.
    • How to make the Kubernetes deployment wait for build image before deploying the application.

    Analyzing these problems, we see that they do not apply only to this use case. These are common issues for developers who want to build and deploy Java or other applications on Kubernetes.

    So, what is the solution?  Let's address them one by one:

    How to build a container image natively on Kubernetes

    At this point, Kubernetes does not provide any out-of-the-box way to build applications natively on Kubernetes, that is, something like kubectl build myapp. This made us look for something that can do a build on Kubernetes; fortunately, we have Knative Build that does the work for us.

    "What? Knative build? I'm not running a serverless application." That's a usual reaction from developers when we talk about Knative build. To be clear, Knative build is not just for the serverless world; it can be used with any Kubernetes cluster without the need for any other Knative components and Istio. With just Knative build installed in a Kubernetes cluster, the builds can be run to make Linux container images out of the given source code.

    How to make the Kubernetes deployment wait for build image before deploying the application

    The Kubernetes deployment has to wait for the build to complete before starting to deploy itself. The solution to this problem is to use Init Containers. Adding an init container to the Kubernetes deployment makes the pod’s containers start in a sequence based on the completion state of the previous container in the chain.

    If one of the init containers fails, then the whole deployment is deemed failed with the init container being restarted. The following diagram explains how the pattern works inside Kubernetes.

    Init Container Pattern

    For example, here is a Kubernetes deployment using init containers (see line #31-36):

    https://gist.github.com/kameshsampath/b219a1c8cb803233878cc8085426ab46

    You can find a complete end-to-end example here and instructions on how to get a Quarkus application built and deployed to your Kubernetes cluster. My colleagues Roland Huß and Bilgin Ibryam have written an excellent book, called Kubernetes Patterns, which explains many patterns that are applicable to everyday cloud-native application development.

    If you want to learn more about Knative basics, check out our multi-hour detailed Knative tutorial, which offers demonstrations and explains concepts in a simple and easy way.

    Last updated: September 23, 2019

    Recent Posts

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue