Creating Kata Containers
Create an NGINX pod that runs as a Kata Container using a Kubernetes
RuntimeClass.
This task shows how to create a container using kata-runtime as the
runtime engine. To create Kata Containers, set up a Kubernetes RuntimeClass
resource for kata-runtime. For information on setting up a
RuntimeClass, see Setting Runtime Classes.
This example uses a Kubernetes pod configuration file to create a Kata Container running an NGINX web server.
- Create pod configuration file.
On a host that's set up to use the
kubectlcommand to connect to the Kubernetes cluster, create a Kubernetes pod configuration file. Use the notationruntimeClassName: kata-containersin the pod file. When CRI-O finds this runtime class in a pod file, it useskata-runtimeto run the container.This pod file is named
kata-nginx.yaml.apiVersion: v1 kind: Pod metadata: name: kata-nginx spec: runtimeClassName: kata-containers containers: - name: nginx image: container-registry.oracle.com/olcne/nginx:1.17.7 ports: - containerPort: 80 - Start the pod.
Create the Kata Container using the
kata-nginx.yamlfile with thekubectl applycommand:kubectl apply -f kata-nginx.yaml - Verify the pod is running.
To check the pod has been created, use the
kubectl get podscommand:kubectl get podsThe output looks similar to:
NAME READY STATUS RESTARTS AGE kata-nginx 1/1 Running 0 40s - Show more information about the pod.
Use the
kubectl describecommand to show a more detailed view of the pod, including the runtime, which worker node is hosting the pod, and the Container ID.kubectl describe pod kata-nginxThe output looks similar to:
Name: kata-nginx Namespace: default Priority: 0 Runtime Class Name: kata-containers Service Account: default Node: ocne-worker-1/<IP_address> Start Time: Wed, 23 Oct 2024 12:07:35 +0000 Labels: <none> Annotations: <none> Status: Running IP: 10.244.1.29 IPs: IP: 10.244.1.29 Containers: nginx: Container ID: cri-o://ca0559ab7c77deddb2a5baf681fff39ae620a5a0696ee4535ad53fff... Image: container-registry.oracle.com/olcne/nginx:1.17.7 Image ID: container-registry.oracle.com/olcne/nginx@sha256:78ce89068e7feb1... Port: 80/TCP Host Port: 0/TCP State: Running ... - Start an administration console on the worker node running the Kata Container
pod.
You can start an administration console on any Kubernetes node using the
ocne cluster consolecommand. The syntax is:ocne cluster console[{-d|--direct}] {-N|--node} nodename [{-t|--toolbox}] [-- command]For more information on the syntax options, see Oracle Cloud Native Environment: CLI.
Start an administration console on the worker node running thekata-containerpod identified in the output of the previous step, by entering the following command, replacing the name of the node as appropriate:ocne cluster console --direct --node ocne-worker-1 - List the pods running on a worker node.
List the pods running on a worker node using the
crictl podscommand by running the following command at the administration console prompt:sudo crictl podsThe output looks similar to:
POD ID CREATED STATE NAME NAMESPACE ... 02ab970089cd1 11 seconds ago Ready console-ocne-worker-1... ocne-system ... 52af794c70dce 4 minutes ago Ready kata-nginx default ... 430c83360e934 6 days ago Ready control-plane-capi-cont... capi-kubeadm-con... ac94aebe63b51 6 days ago Ready bootstrap-capi-controll... capi-kubeadm-boo... ...You can see the
kata-nginxcontainer is running on this worker node.For more information on using the
crictlcommand, use thecrictl --helpcommand. - List details about the containers running on a worker node.
To get more detailed information about the containers on a worker node, use the
crictl pscommand. For example:sudo crictl psThe output looks similar to:
CONTAINER IMAGE ... NAME POD ID ... 43d8e4fba2698 9a7fadacb497dbc... console-ocne-worker-1 2e4655ea682e5 ... ca0559ab7c77d ...nginx@sha256... nginx 52af794c70dce ... 1556b7459a2be container-regis... olcne/kubeadm-control-plane-cont 430c83360e934 ... ...Note the Container ID is a shortened version of the
Container IDshown in the pod description. - List more details about a pod.
To get detailed information about a pod, run the
crictl inspectpcommand using thePOD ID. For example:sudo crictl inspectp 52af794c70dceThe output looks similar to:
{ "status": { "id": "52af794c70dce199e1bdab40b9dfe196def5a791266240a11e3477ea66b1421e", "metadata": { "attempt": 0, "name": "kata-nginx", "namespace": "default", "uid": "331dc2b0-769b-4a5e-b1eb-a521f8c75670" }, "state": "SANDBOX_READY", "createdAt": "<date>", "network": { "additionalIps": [], "ip": "<IP_address>" }, ... - Exit the administration console.
Exit the administration console on the worker node by typing
exitat the console prompt.exit - Delete the pod.
You can delete the pod using the
kubectl deletecommand on the host:kubectl delete pod kata-nginx