Kubernetes Application – Package Multiple Resources Together

Deploying an application in Kubernetes require to create multiple resources such as Pods, Services, Replication Controllers, and others. Typically each resource is define in a configuration file and created using kubectl script. But if multiple resources need to be created then you need to invoke kubectl multiple times. So if you need to create the following resources:

  • MySQL Pod
  • MySQL Service
  • WildFly Replication Controller

Then the commands would look like:

Or for convenience, wrap these invocations in a shell script. But that is not very intuitive! There is a better, and more natural and intuitive way.

Kubernetes allow multiple resources to be specified in a single configuration file. This allows to create a “Kubernetes Application” that can consists of multiple resources easily.

Previous section showed how to deploy the Java EE application using multiple configuration files. This application can be delpoyed using a single configuration file as well.

An application, as discussed above, consisting of MySQL Pod, MySQL Service, and WildFly Replication Controller can be created using the following configuration file:

Notice that each section, one each for MySQL Pod, MySQL Service, and WildFly Replication Controller, is separated by ----.

Such an application can be created as:

Complete details about how to setup Kubernetes and run this application are available at github.com/arun-gupta/kubernetes-java-sample/#kubernetes-application.

More details about creating a Kubernetes application with multiple resources can be found in #12104.

You can learn about how to create Kubernetes resources for a Java application, or otherwise, at github.com/arun-gupta/kubernetes-java-sample/.

Be Sociable, Share!
  • Tweet

5 thoughts on “Kubernetes Application – Package Multiple Resources Together

  1. Very Nice Article , Thank You for sharing an important information http://www.vaysinfotech.com/job/software-developer-java-developer/

  2. I am creating a wordpress sample app. I have a rc running mysql and a service for mysql. I’m attempting to bring up the wordpress rc, but would like to know if there’s a way to automatically point my yaml config for the wordpress rc to the mysql db’s svc (which would be the WORDPRESS_DB_HOST ip and port. What I’m doing now is a kubectl get svc to get the mysql service’s IP address and then substitution the information in my wordpress rc’s yaml manually.

  3. Really nice article Arun, but think there is an issue with your YAML.

    The YAML separator “—-” should be “—“.

    I copied your code directly into my machine and faced YAML syntax error “error: error converting YAML to JSON: yaml: line 31: could not find expected ‘:’ “.

    Took a while to debug the same, as the code was all looking good, just making that change worked.

  4. I’ve just tried to download the Interactive Tutorial, but failed. It was blocked by the antivirus. Is it normal? How can I get the document?
    Thanks,
    Sven Taow
    achieveessays
    Kubernetes Application reviews.

Leave a Reply

Your email address will not be published. Required fields are marked *