Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      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
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java 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

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • 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

That app you love, part 8: A blueprint for "that app you love"

October 20, 2016
N. Harrison Ripps
Related topics:
ContainersDeveloper ToolsKubernetesMicroservices
Related products:
Red Hat OpenShift Container Platform

Share:

    Welcome to the eighth installment of That App You Love, a blog series in which I show you how to you can make almost any app into a first-class cloud citizen. If you want to start from the beginning, jump back and check out Part 1: Making a Connection. You’ll need the docker service and the oc utility to follow along in this post; for instructions check out Part 5: Upping Our (Cloud) Game.

    In Part 7 we learned how to expose container-level environment variables up at the cloud level, and we also got our first taste of Templates and Deployments. Crafting a Template for our ZNC container image that defines those environment variables - and the rules for setting them - is a major step in improving the app’s reusability and basic security. But forget about ZNC because we’re really talking about That App You Love, and what it takes to make it rock the cloud!

    Templates and Parameters: Process, Load, Win!

    By the end of Part 7, we had added 3 environment variables to the Deployment object of our app. The values of those variables were hard-coded, and the password was very easy to guess. If we made a template that included those variables with those values, there’s a good chance that everyone who used that template would end up creating an app deployment with the same username and password. That’s bad.

    Luckily, OpenShift templates support a set of rules, called Parameters, for describing how variables should be populated. Parameters are processed at the time when the objects in the template are created, meaning that every use of a template can result in different settings.

    To see what I mean, try this out:

    1. If you are still running “oc cluster up” from Part 7, it is easiest to start with a clean slate, so run:
      sudo <path_to>/oc cluster down; sudo <path_to>/oc cluster up
      oc login -u developer -p developer --server=<server_IP>:8443

      (If you don’t have a docker environment and the “oc” binary yet, jump back to Part 5 and then come back when your cluster is running.)

    2. Let’s grab a new version of our app template, using wget or curl:
      wget https://raw.githubusercontent.com/nhr/znc-cluster-app/master/znc-template-with-params.yaml
      
    3. Next, process and load the template with this combo-command:
      oc process -v ZNC_USER=clouduser,ZNC_NAME=CloudUser -f znc-template-with-params.yaml | oc create -f -
      
    4. And finally, kick off the Deployment object that we just created:
      oc deploy dc/znc-cluster-app --latest

    Cool right? Ah - except what actually happened?

    Rules of Engagement

    Have a look at the environment variables inside the Deployment object with this command:

    oc get dc/znc-cluster-app -o yaml | sed -n -e '/env:/,$p' | head -7

    You should get output like:

         - env:
            - name: ZNC_USER
              value: clouduser
            - name: ZNC_PASS
              value: F8fpyfBYFl2pBhGq
            - name: ZNC_NAME
              value: CloudUser

    (Note that you can also see these by inspecting the Deployment object from your OpenShift console - navigate to Applications => Deployments => znc-cluster-app and click the Environment tab.)

    The ‘clouduser’ and ‘CloudUser’ values are familiar because we passed them in, but where did that crazy password come from?

    Let’s go back and have a look at that template file we are working with, using this command:

    cat znc-template-with-params.yaml | tail -13

    You should see the wiring behind the boards, which looks like this:

    parameters:
      - name: ZNC_NAME
        description: The display name for the first ZNC user account
        value: Administrator
        required: true
      - name: ZNC_USER
        description: The username for the first ZNC user account
        value: admin
        required: true
      - name: ZNC_PASS
        description: The password for the first ZNC user account
        generate: expression
        from: "[a-zA-Z0-9]{16}"

    Recall that we processed and loaded this template with a combination of two commands (above, in step 3):

    • oc process reads a template and dynamically replaces placeholders with values that can be provided, generated, or defaulted. In our case we replaced ZNC_NAME and ZNC_USER with our own values. “oc process” then transforms the contents of the template into JSON representations of actual objects.
    • oc create reads a file and creates one or more objects in the cluster based on the contents of the file.

    Net result: because we’ve mapped these parameters to the values of the environment variables defined in our Deployment, every time anyone processes our template, a different password is going to get generated. Now we can share this template and enable people to deploy That App You Love without creating a basic, widespread security problem.

    Whack-a-Pod

    For our last trick today, it is useful to understand that while the template now provides us basic security (which we can upon), the OpenShift cluster itself is also providing us with a fair measure of robustness. Check this out:

    1. Find the name of your running ZNC pod:
      oc get pods

      (It will be something like “znc-cluster-app-1-1yb3d”)

    2. Kill the pod with “oc delete”
      oc delete pod <pod_name>
      
    3. Re-list the pods on the cluster:
      oc get pods

    If you run step #3 fast enough, you may catch the cluster with output like this:

    NAME                      READY     STATUS              RESTARTS
    znc-cluster-app-1-1yb3d   1/1       Terminating         0
    znc-cluster-app-1-vae7x   0/1       ContainerCreating   0

    The pod you deleted is briefly in Terminating state, meanwhile a brand new copy of the pod is already spinning up.

    Why did this happen? Another component of the application that was created when we first ran “oc new-app” is a ReplicationController, or ‘rc’. The rc’s job is to make sure that the cluster is always running our desired number of app copies (which is 1 in our case).

    If you play around with the new copy of your pod, you’ll find that it starts with the same settings as the previous one, and any changes you may have made to the original Pod are lost. It’s time to tackle that last challenge of cloud deployments - in the next post we’ll learn how to use attached storage to bring statefulness to the stateless environment of That App You Love!

    See you next time in Part 9: Storage and Statefulness!

    This series will run every Tuesday and Thursday until we've accomplished our goals, so stay tuned in, subscribe, and thanks for reading!

    Title Date
    That app you love, part 1: Making a connection 2016/09/27
    That app you love, part 2: Immutable but flexible – What settings matter? 2016/09/29
    That app you love, part 3: Every setting in its place 2016/10/04
    That app you love, part 4: Designing a config-and-run container 2016/10/06
    That app you love, part 5: Upping our (cloud) game 2016/10/11
    That app you love, part 6: Container, meet cloud 2016/10/13
    That app you love, part 7: Wired for sound 2016/10/18
    That app you love, part 8: A blueprint for “that app you love” 2016/10/20
    That app you love, part 9: Storage and statefulness 2016/10/25
    That app you love, part 10: Long live “that app you love” 2016/10/27

     

    About the Author

    Hi there! My name is N. Harrison Ripps, and I am an engineer and people manager on the Containers team at Red Hat. Together with the greater open source community, our team has taken the combination of the docker container format and Google’s Kubernetes orchestration system, and then extended this framework with a number of administrator- and developer-friendly features that we call the OpenShift Container Platform.

    Last updated: March 17, 2023

    Recent Posts

    • Build container images in CI/CD with Tekton and Buildpacks

    • How to deploy OpenShift AI & Service Mesh 3 on one cluster

    • JVM tuning for Red Hat Data Grid on Red Hat OpenShift 4

    • Exploring Llama Stack with Python: Tool calling and agents

    • Enhance data security in OpenShift Data Foundation

    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