How can I create a single Ubuntu Pod in a Kubernetes or OpenShift cluster?. In Kubernetes a Pod is a group of one or more containers, with shared storage/network resources, and a specification for how to run the containers.
When a Pod running a single container you can think of a it as a wrapper around a single container. Kubernetes manages Pods rather than managing the containers directly.
In this tutorial we will look at how you can deploy an Ubuntu Pod in Kubernetes or OpenShift cluster. This can be for Debug purposes or just testing network connectivity to other Pods and Services in the namespace.
Since Pods are designed as relatively ephemeral and disposable entities you should never run Production container workloads by creating Pods directly. Instead, create them using workload resources such as Deployment.
We will create a sleep container from Ubuntu docker image using latest tag. Below is the Pod creation YAML contents.
apiVersion: v1 kind: Pod metadata: name: ubuntu labels: app: ubuntu spec: containers: - name: ubuntu image: ubuntu:latest command: ["/bin/sleep", "3650d"] imagePullPolicy: IfNotPresent restartPolicy: Always
You can run below kubectl commands to deploy the Pod in the current namespace:
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Pod metadata: name: ubuntu labels: app: ubuntu spec: containers: - name: ubuntu image: ubuntu:latest command: ["/bin/sleep", "3650d"] imagePullPolicy: IfNotPresent restartPolicy: Always EOF
Check the Pod’s status:
$ kubectl get pod ubuntu NAME READY STATUS RESTARTS AGE ubuntu 1/1 Running 0 34s
Access Pod’s shell
Once you confirm the Pod is running you can access its shell session with kubectl or oc command.
Using kubectl command:
kubectl exec --stdin --tty ubuntu -- /bin/bash
To quit shell use exit command:
[email protected]:/# exit exit
Using oc command:
$ oc rsh --shell=/bin/bash ubuntu [email protected]:/# exit exit
Installing Package in an Ubuntu Pod
You can use standard ubuntu apt package management tool for installation and removal of software packages.
Example below install telnet into the Ubuntu container.
$ kubectl exec --stdin --tty ubuntu -- /bin/bash [email protected]:/# apt update [email protected]:/# apt install telnet Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: netbase The following NEW packages will be installed: netbase telnet 0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded. Need to get 77.2 kB of archives. After this operation, 207 kB of additional disk space will be used. Do you want to continue? [Y/n] y
Confirm that we can use telnet installed.
[email protected]:/# telnet 10.10.6.5 8080 Trying 10.10.6.5... Connected to 10.10.6.5. Escape character is '^]'. E��^] telnet> quit Connection closed.
We have confirmed that our Pod is usable. Check other good guides we have on containers: