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

Run OpenShift sandboxed containers with hosted control planes

Maximize efficiency and workload isolation

May 24, 2024
Camilla Conte Adel Zaalouk
Related topics:
ContainersKubernetes
Related products:
Red Hat OpenShift

Share:

    Hosted control planes, available via the multi-cluster engine, has been generally available since Red Hat OpenShift 4.14. Hosted control planes reduce costs and improve productivity for organizations adopting a multi-cluster approach.

    OpenShift sandboxed containers, based on Kata Containers, and generally available since OpenShift 4.8, is a native Kubernetes CRI runtime that provides an additional layer of isolation for workloads through hardware virtualization.

    When used together, hosted control planes and OpenShift sandboxed containers offer several benefits, such as speed, separation of concerns, and the necessary hardening to run multi-tenant workloads with stringent security constraints. 

    This article provides a detailed guide on how to configure and run sandboxed workloads for OpenShift clusters with hosted control planes, maximizing efficiency and workload isolation.

    Prerequisites

    In order to conduct this process, you need an OpenShift cluster already running, and a hosted control plane already configured. You don't need a node pool yet.

    We’ll use the oc and hcp command-line tools. Access credentials must be already set up.

    We recommend that you have already practiced setting up a node pool for your hosted control plane on your current cluster. Apart from that, completing these instructions should be as simple as creating a few Kubernetes resources from files.

    Create MachineConfig

    The first resource we will create is a MachineConfig. All the nodes using this MachineConfig will install the sandboxed-containers Red Hat Enterprise Linux CoreOS extension. Create the file sandboxed-containers-mc.yaml, with the following content:

    apiVersion: machineconfiguration.openshift.io/v1
    kind: MachineConfig
    metadata:
     name: sandboxed-containers-mc
    spec:
     extensions:
        - sandboxed-containers

    To link a MachineConfig to a node pool, we need to put the MachineConfig in a ConfigMap. Here we create the ConfigMap sandboxed-containers-mc-cm out of the sandboxed-containers-mc.yaml file:

    oc create configmap sandboxed-containers-mc-cm -n clusters --from-file config=sandboxed-containers-mc.yaml

    Create a node pool

    Now it's time to create a new node pool. The new node pool must use the sandboxed-containers MachineConfig. We also want to have a dedicated label for all the nodes in the node pool.

    Depending on the platform you are going to deploy on, the create nodepool command has different arguments. Use the same command and arguments that you already practiced when creating other node pools. Add the --render argument, and save the output to a file, node-pool.yaml:

    hcp create nodepool [...] --render > node-pool.yaml

    Now we have the file node-pool.yaml. We extend the file with the additional config and label, as in the snippet below:

    [...]
    spec:
     config:
       - name: "sandboxed-containers-mc-cm"
     nodeLabels:
       node-role.kubernetes.io/kata-oc: ""
    [...]

    Finally we create the node pool by applying the file node-pool.yaml:

    oc create -f node-pool.yaml

    We wait to see the new nodes up and running before continuing to the next section. You may see the nodes rebooting once, as part of the Red Hat Enterprise Linux CoreOS extension installation process.

    Depending on the platform you deploy on, additional steps might be necessary. For example, when using the “None” platform, you need further manual steps to deploy the workers. This is covered in the hosted control planes documentation.

    Create RuntimeClass

    In the previous section, we created a node pool. The MachineConfig mechanism installed the sandboxed-containers extension on the new nodes. Now, for pods to run in the sandboxed runtime, we need to create the kata RuntimeClass.

    Create the file runtime-class.yaml with the following content:

    apiVersion: node.k8s.io/v1
    handler: kata
    kind: RuntimeClass
    metadata:
     name: kata
    overhead:
     podFixed:
       cpu: 250m
       memory: 350Mi
    scheduling:
     nodeSelector:
       node-role.kubernetes.io/kata-oc: ""

    Prepare to access the hosted cluster. In the following steps we use oc with the --kubeconfig option to make sure we’re running commands on the hosted cluster. See the following example:

    oc --kubeconfig ${HOSTED_CLUSTER_NAME}.kubeconfig ...

    Apply the kata RuntimeClass to the hosted cluster:

    oc --kubeconfig ${HOSTED_CLUSTER_NAME}.kubeconfig apply -f runtime-class.yaml

    Run a sandboxed workload

    Everything should be set. In the previous step, we created the kata RuntimeClass to select the sandboxed-containers runtime. Now we will create a simple pod that uses the kata RuntimeClass. Then we show that the pod is running in a sandbox as expected.

    We start a pod with the kata RuntimeClass. For the sake of the example, a web server keeps the pod running indefinitely. Be mindful that you have to use the hosted cluster kubeconfig here, like in the previous step.

    oc --kubeconfig ${HOSTED_CLUSTER_NAME}.kubeconfig \
    run --image=registry.fedoraproject.org/fedora \
    --overrides='{"spec":{"runtimeClassName":"kata"}}' \
    test-pod-sandboxed -- python3 -m http.server

    We inspect the pod to tell which node it’s running on:

    oc describe pod test-pod-sandboxed | grep 'Node:'

    We get a shell on the worker node where the pod is running on. On the worker node, we show the qemu-kvm processes:

    ps -ef | grep qemu

    Check the output of the previous command, you should see the process of the Kata sandbox, something like the following:

    qemu-kvm -name sandbox-...

    That’s it. QEMU is running your pod in a virtual machine sandbox, managed with a hosted control plane!

    More Information 

    For more information, visit the documentation: 

    • Hosted control planes | OpenShift Container Platform 4.15
    • OpenShift sandboxed containers user guide

    If you need further assistance, you can reach out to us through the following methods:

    • OpenShift Commons slack
    • OpenShift users Kubernetes slack channel
    • Through your Red Hat account representative

    Related Posts

    • How to install single node OpenShift on bare metal

    • How to manage a fleet of heterogeneous OpenShift clusters

    • Set up an OpenShift cluster to deploy an application in odo CLI

    • Ensure a scalable and performant environment for ROSA with hosted control planes

    • Use OperatorPolicy to manage Kubernetes-native applications

    • What's new for developers in Red Hat OpenShift 4.15

    Recent Posts

    • How Kafka improves agentic AI

    • How to use service mesh to improve AI model security

    • How to run AI models in cloud development environments

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    What’s up next?

    Get a hands-on introduction to daily life as a developer crafting code on OpenShift, the open source application development platform from Red Hat, with OpenShift for Developers.

    Get the e-book
    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