How to Build Multi‑Environment Pods with CentOS, Ubuntu, Debian, and More
Step 1: Create Namespaces
kubectl create namespace mqmdev
kubectl create namespace mqmtest
kubectl create namespace mqmprod
Step 2: Create Pods (example with 7 OS containers)
Save YAML files (mqmdev.yaml, mqmtest.yaml, mqmprod.yaml) with multiple containers inside each pod.
Example for mqmtest:
apiVersion: v1
kind: Pod
metadata:
name: mqmtest-pod
namespace: mqmtest
spec:
containers:
- name: centos-container
image: centos:7
command: ["/bin/bash", "-c", "sleep infinity"]
- name: redhat-container
image: registry.access.redhat.com/ubi8/ubi
command: ["/bin/bash", "-c", "sleep infinity"]
- name: ubuntu-container
image: ubuntu:22.04
command: ["/bin/bash", "-c", "sleep infinity"]
- name: debian-container
image: debian:stable
command: ["/bin/bash", "-c", "sleep infinity"]
- name: fedora-container
image: fedora:latest
command: ["/bin/bash", "-c", "sleep infinity"]
- name: oraclelinux-container
image: oraclelinux:8
command: ["/bin/bash", "-c", "sleep infinity"]
- name: alpine-container
image: alpine:latest
command: ["/bin/sh", "-c", "sleep infinity"]
Apply:
kubectl apply -f mqmdev.yaml
kubectl apply -f mqmtest.yaml
kubectl apply -f mqmprod.yaml
Step 3: Check Pod Status
kubectl get pods -n mqmdev
kubectl get pods -n mqmtest
kubectl get pods -n mqmprod
Step 4: List Container Names Inside a Pod
kubectl get pod mqmtest-pod -n mqmtest -o jsonpath="{.spec.containers[*].name}"
Output example:
centos-container redhat-container ubuntu-container debian-container fedora-container oraclelinux-container alpine-container
Step 5: Connect to a Particular Container
Use kubectl exec with -c <container-name>:
# CentOS
kubectl exec -it mqmtest-pod -n mqmtest -c centos-container -- /bin/bash
# Red Hat UBI
kubectl exec -it mqmtest-pod -n mqmtest -c redhat-container -- /bin/bash
# Ubuntu
kubectl exec -it mqmtest-pod -n mqmtest -c ubuntu-container -- /bin/bash
# Debian
kubectl exec -it mqmtest-pod -n mqmtest -c debian-container -- /bin/bash
# Fedora
kubectl exec -it mqmtest-pod -n mqmtest -c fedora-container -- /bin/bash
# Oracle Linux
kubectl exec -it mqmtest-pod -n mqmtest -c oraclelinux-container -- /bin/bash
# Alpine (use sh instead of bash)
kubectl exec -it mqmtest-pod -n mqmtest -c alpine-container -- /bin/sh
Step 6: Verify OS Inside Container
Once inside, run:
cat /etc/os-release
This confirms which OS environment you’re connected to.
✅ Summary
Create namespaces → mqmdev, mqmtest, mqmprod.
Apply pod YAMLs with 7 containers each.
Check pod status → kubectl get pods -n <namespace>.
List container names → kubectl get pod <pod> -n <namespace> -o jsonpath=....
Connect to container → kubectl exec -it ... -c <container-name> -- /bin/bash.
Verify OS → cat /etc/os-release.
No comments:
Post a Comment