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 7: Wired for sound

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

Share:

    Welcome to the seventh 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 6 of our adventure, we learned how to launch a containerized version of ZNC on the OpenShift Container Platform with a single command - “oc new-app”. But forget about ZNC - we’re really talking about That App You Love, and in this post we’re going to learn how to expose the configurable settings that you care about, along with a few other concepts that will make your app’s cloud experience better.

    Let’s Fast-Forward to the Good Stuff

    Because our mini-cluster (see Part 5 if you need to set this up) is stateless, any of the work we did in Part 6 disappeared the moment we stopped the cluster. But rather than starting from scratch, we can “fast-forward” to where we were by creating our app and adding a Route all in one go.

    To do this, we’ll use a Template that includes everything that OpenShift Container Platform needs to know about our app to put everything back in place.

    1. If the docker service and OpenShift Container Platform cluster aren’t running, fire them up. Shortcut for Fedora users:
      sudo systemctl start docker
      sudo <path_to>/oc cluster up
      oc login -u developer -p developer --server=<server_IP>:8443
      
    2. Grab a copy of this template file using wget or curl:
      wget https://raw.githubusercontent.com/nhr/znc-cluster-app/master/znc-template-basic.yaml
    3. Run “oc process” to turn the template into a list of objects, and pipe the output to “oc create” to instantiate them:
      oc process -f znc-template-basic.yaml | oc create -f -
      
    4. Finally, run “oc deploy” to tell OpenShift to get things rolling:
      oc deploy dc/znc-cluster-app --latest
      

    That’s it! You can check on the deployment progress with:

    oc status

    If you deployed the app along with us back in Part 6, this should go pretty quickly. If you’re just jumping in, it will take a few minutes to download our sample app and some other containers.

    So what just happened there, and what is that “template” file? We’re going to talk about templates a lot in Part 8, because they make it easy to deploy a number of objects at the same time. But for now, let’s move on to:

    Environment Variables in the Cloud

    We know that our app container is running as a Pod in our cluster, and down in the container environment we know we’ve got some environment variables. For review, they are:

    • ZNC_USER - sets the username of the initial user account
    • ZNC_PASS - sets the password of the initial user account
    • ZNC_NAME - sets the display name of the initial user account

    How do we start to hook these up so that we can change these values when our container is deployed? For this, check out the “oc set env” command:

    1. First, run “oc set env” to create and set the variables:
      oc set env dc/znc-cluster-app -e ZNC_USER=znc ZNC_PASS=znc ZNC_NAME=ZNC
      
    2. Next, tell OpenShift to re-deploy our application:
      oc deploy dc/znc-cluster-app --latest
      
    3. Finally, navigate to the route (a “xip.io” address) for your app. You can find the route to use by running:
      oc get routes
      

      And then navigating to:

      https://<xip.io address>/
      

      (You can use the Service IP / Service Port address if the xip.io address doesn’t work)

    You should see the same ZNC web console page that we remember, but now the “admin” / “admin” username / password combo won’t get you in - you’ve got to use “znc” / “znc” instead. This is a really powerful detail of Kubernetes and the OpenShift Container Platform. We just set some environment variables up at the cloud layer, and they’ve automatically found their way all the way back to ZNC’s config file within a running container.

    The values we used when we created our environment variables were all hard-coded values. That’s okay for now. We’re going to learn how to turn those variables into configurable parameters later. Right now we need to give some love to the cloud object that knows everything about That App You Love, and that’s...

    Deployments - Another Cloud Part

    From Part 6 we know about Pods, Services and Routes. So what is a Deployment? A Deployment (a.k.a. DeploymentConfig, or just ‘dc’ to its friends) tells us:

    • What Pod to run
    • How many copies of it to run
    • A bunch of metadata about the Pod including environment variables
    • How to know when to trigger a redeployment
    • 5 amazing Linux tricks - number 3 blew my mind!

    In Part 6, when we ran “oc new-app” to deploy our container, OpenShift created a Deployment object that tells Kubernetes how to launch our app in a repeatable way. Following on that, in our examples above, you may notice that we didn’t run “oc set env” against our Pod. The “dc/znc-cluster-app” target for our command? That’s our app’s Deployment object.

    Why did we just add our environment variable definitions to the Deployment, and not directly to the Pod? Environment variables added to a Pod are lost when the Pod disappears. By defining them in the Deployment instead, every deployed Pod will always include them.

    Well that’s great, but how do we really open up those settings so that we can customize every deployment of That App You Love? Tune in for Part 8: A Blueprint for That App You Love!

    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

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    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

    Red Hat legal and privacy links

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

    Report a website issue