Chapter 3. Configure
You can configure OpenShift sandboxed containers for Amazon Web Services (AWS).
Perform the following steps:
- Enable ports to allow internal communication with peer pods.
- Create the peer pods config map.
-
Create the
KataConfigcustom resource. - Optional: Modify the number of peer pod VMs running on each worker node.
- Verify the pod VM image.
- Disable insecure options by customizing the Kata Agent policy.
- Optional: If you select a custom peer pod VM image from an authenticated registry, configure a pull secret.
- Optional: Select a custom peer pod VM image.
- Configure your workload for OpenShift sandboxed containers.
3.1. Enabling ports Copy linkLink copied to clipboard!
You must enable ports 15150 and 9000 to allow internal communication with peer pods running on AWS.
Prerequisites
- You have installed the OpenShift sandboxed containers Operator.
- You have installed the AWS command line tool.
-
You have access to the cluster as a user with the
cluster-adminrole.
Procedure
Log in to your OpenShift Container Platform cluster and retrieve the instance ID:
$ INSTANCE_ID=$(oc get nodes -l 'node-role.kubernetes.io/worker' \ -o jsonpath='{.items[0].spec.providerID}' | sed 's#[^ ]*/##g')Retrieve the AWS region:
$ AWS_REGION=$(oc get infrastructure/cluster -o jsonpath='{.status.platformStatus.aws.region}')Retrieve the security group IDs and store them in an array:
$ AWS_SG_IDS=($(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} \ --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' \ --output text --region $AWS_REGION))For each security group ID, authorize the peer pods shim to access kata-agent communication, and set up the peer pods tunnel:
$ for AWS_SG_ID in "${AWS_SG_IDS[@]}"; do \ aws ec2 authorize-security-group-ingress --group-id $AWS_SG_ID --protocol tcp --port 15150 --source-group $AWS_SG_ID --region $AWS_REGION; \ aws ec2 authorize-security-group-ingress --group-id $AWS_SG_ID --protocol tcp --port 9000 --source-group $AWS_SG_ID --region $AWS_REGION; \ done
The ports are now enabled.
3.2. Creating the peer pods config map Copy linkLink copied to clipboard!
You must create the peer pods config map.
Prerequisites
- You have an Amazon Machine Image (AMI) ID if you are not using the default AMI ID based on your cluster credentials.
Procedure
Obtain the following values from your AWS instance:
Retrieve and record the instance ID:
$ INSTANCE_ID=$(oc get nodes -l 'node-role.kubernetes.io/worker' \ -o jsonpath='{.items[0].spec.providerID}' | sed 's#[^ ]*/##g')This is used to retrieve other values for the secret object.
Retrieve and record the AWS region:
$ AWS_REGION=$(oc get infrastructure/cluster \ -o jsonpath='{.status.platformStatus.aws.region}') \ && echo "AWS_REGION: \"$AWS_REGION\""Retrieve and record the AWS subnet ID:
$ AWS_SUBNET_ID=$(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} \ --query 'Reservations[*].Instances[*].SubnetId' --region ${AWS_REGION} \ --output text) && echo "AWS_SUBNET_ID: \"$AWS_SUBNET_ID\""Retrieve and record the AWS VPC ID:
$ AWS_VPC_ID=$(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} \ --query 'Reservations[*].Instances[*].VpcId' --region ${AWS_REGION} \ --output text) && echo "AWS_VPC_ID: \"$AWS_VPC_ID\""Retrieve and record the AWS security group IDs:
$ AWS_SG_IDS=$(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} \ --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' \ --region $AWS_REGION --output json | jq -r '.[][][]' | paste -sd ",") \ && echo "AWS_SG_IDS: \"$AWS_SG_IDS\""
Create a
peer-pods-cm.yamlmanifest file according to the following example:apiVersion: v1 kind: ConfigMap metadata: name: peer-pods-cm namespace: openshift-sandboxed-containers-operator data: CLOUD_PROVIDER: "aws" VXLAN_PORT: "9000" PROXY_TIMEOUT: "5m" PODVM_INSTANCE_TYPE: "t3.medium" PODVM_INSTANCE_TYPES: "t2.small,t2.medium,t3.large" PODVM_AMI_ID: "<podvm_ami_id>" AWS_REGION: "<aws_region>" AWS_SUBNET_ID: "<aws_subnet_id>" AWS_VPC_ID: "<aws_vpc_id>" AWS_SG_IDS: "<aws_sg_ids>" TAGS: "key1=value1,key2=value2" PEERPODS_LIMIT_PER_NODE: "10" ROOT_VOLUME_SIZE: "6" DISABLECVM: "true"PODVM_INSTANCE_TYPE- Defines the default instance type that is used if the instance type is not defined in the workload object.
PODVM_INSTANCE_TYPES- Specify the allowed instance types, without spaces, for creating the pod. You can define smaller instance types for workloads that need less memory and fewer CPUs or larger instance types for larger workloads.
PODVM_AMI_ID-
This value is populated when you run the
KataConfigCR, using an AMI ID based on your cluster credentials. If you create your own AMI, specify the correct AMI ID. TAGS-
You can configure custom tags as
key:valuepairs for pod VM instances to track peer pod costs or to identify peer pods in different clusters. PEERPODS_LIMIT_PER_NODE-
You can increase this value to run more peer pods on a node. The default value is
10. ROOT_VOLUME_SIZE- You can increase this value for pods with larger container images. Specify the root volume size in gigabytes for the pod VM. The default and minimum size is 6 GB.
Create the config map by running the following command:
$ oc create -f peer-pods-cm.yaml
3.3. Create the KataConfig custom resource Copy linkLink copied to clipboard!
You must create the KataConfig custom resource (CR) to install kata-remote as a runtime class on your worker nodes.
Prerequisites
-
Creating the
KataConfigCR automatically reboots the worker nodes. The reboot can take from 10 to more than 60 minutes depending on your deployment size, hardware type, and other factors.
Procedure
Create an
example-kataconfig.yamlmanifest file according to the following example:apiVersion: kataconfiguration.openshift.io/v1 kind: KataConfig metadata: name: example-kataconfig spec: enablePeerPods: true logLevel: info # kataConfigPoolSelector: # matchLabels: # <label_key>: '<label_value>'<label_key>: '<label_value>'-
Optional: If you have applied node labels to install
kata-remoteon specific nodes, specify the key and value, for example,kata-remote: 'true'.
Create the
KataConfigCR by running the following command:$ oc create -f example-kataconfig.yamlThe new
KataConfigCR is created and installskata-remoteas a runtime class on the worker nodes.Wait for the
kata-remoteinstallation to complete and the worker nodes to reboot before verifying the installation.Monitor the installation progress by running the following command:
$ watch "oc describe kataconfig | sed -n /^Status:/,/^Events/p"When the status of all workers under
kataNodesisinstalledand the conditionInProgressisFalsewithout specifying a reason, thekata-remoteis installed on the cluster.Verify the daemon set by running the following command:
$ oc get -n openshift-sandboxed-containers-operator ds/osc-caa-dsVerify the runtime classes by running the following command:
$ oc get runtimeclass+
NAME HANDLER AGE
kata kata 34m
{runtime} {runtime-handler} 152m
+ You can also see the default kata runtime class in addition to kata-remote.
3.3.1. Modifying the number of peer pod VMs per node Copy linkLink copied to clipboard!
You can modify the limit of peer pod virtual machines (VMs) per node by editing the peerpodConfig custom resource (CR).
Procedure
Check the current limit by running the following command:
$ oc get peerpodconfig peerpodconfig-openshift -n openshift-sandboxed-containers-operator \ -o jsonpath='{.spec.limit}{"\n"}'Specify a new value for the
limitkey by running the following command:$ oc patch peerpodconfig peerpodconfig-openshift -n openshift-sandboxed-containers-operator \ --type merge --patch '{"spec":{"limit":"<value>"}}'
3.4. Verifying the pod VM image Copy linkLink copied to clipboard!
After kata-remote is installed on your cluster, the OpenShift sandboxed containers Operator creates a pod VM image, which is used to create peer pods. This process can take a long time because the image is created on the cloud instance. You can verify that the pod VM image was created successfully by checking the config map that you created for the cloud provider.
Procedure
Obtain the config map you created for the peer pods:
$ oc get configmap peer-pods-cm -n openshift-sandboxed-containers-operator -o yamlCheck the
statusstanza of the YAML file.If the
PODVM_AMI_IDparameter is populated, the pod VM image was created successfully.
Troubleshooting
Retrieve the events log by running the following command:
$ oc get events -n openshift-sandboxed-containers-operator --field-selector involvedObject.name=osc-podvm-image-creationRetrieve the job log by running the following command:
$ oc logs -n openshift-sandboxed-containers-operator jobs/osc-podvm-image-creation
If you cannot resolve the issue, submit a Red Hat Support case and attach the output of both logs.
3.5. Customizing the Kata Agent policy Copy linkLink copied to clipboard!
You can configure agent policies to restrict which API requests the kata-agent inside the pod virtual machine (VM) may handle. Policies can be set to block all administrative actions after the container starts, neutralizing the agent as an attack vector during runtime. A custom policy replaces the default policy entirely. To modify specific APIs, include the full policy and adjust the relevant rules.
Procedure
Create an
initdata.tomlfile to modify the default policy:algorithm = "sha256" version = "0.1.0" [data] "aa.toml" = ''' ''' "policy.rego" = ''' package agent_policy default AddARPNeighborsRequest := true default AddSwapRequest := true default CloseStdinRequest := true default CopyFileRequest := true default CreateContainerRequest := true default CreateSandboxRequest := true default DestroySandboxRequest := true default GetMetricsRequest := true default GetOOMEventRequest := true default GuestDetailsRequest := true default ListInterfacesRequest := true default ListRoutesRequest := true default MemHotplugByProbeRequest := true default OnlineCPUMemRequest := true default PauseContainerRequest := true default PullImageRequest := true default ReadStreamRequest := false default RemoveContainerRequest := true default RemoveStaleVirtiofsShareMountsRequest := true default ReseedRandomDevRequest := true default ResumeContainerRequest := true default SetGuestDateTimeRequest := true default SignalProcessRequest := true default StartContainerRequest := true default StartTracingRequest := true default StatsContainerRequest := true default StopTracingRequest := true default TtyWinResizeRequest := true default UpdateContainerRequest := true default UpdateEphemeralMountsRequest := true default UpdateInterfaceRequest := true default UpdateRoutesRequest := true default WaitProcessRequest := true default ExecProcessRequest := false default SetPolicyRequest := false default WriteStreamRequest := false default ExecProcessRequest := false '''The default policy allows all API calls. Adjust the
trueorfalsevalues to customize the policy further based on your needs.Convert the
initdata.tomlfile to a Base64-encoded string by running the following command:$ cat initdata.toml | gzip | base64 -w0 > initdata.txtRecord this string to use in the pod manifest.
Add the Base64-encoded initdata string to the
my-pod.yamlmanifest:apiVersion: v1 kind: Pod metadata: name: my-pod annotations: io.katacontainers.config.hypervisor.cc_init_data: <initdata_string> spec: runtimeClassName: kata-remote containers: - name: <container_name> image: registry.access.redhat.com/ubi9/ubi:latest command: - sleep - "36000" securityContext: privileged: false seccompProfile: type: RuntimeDefaultCreate the pod by running the following command:
$ oc create -f my-pod.yaml
3.6. Configuring a pull secret for peer pods Copy linkLink copied to clipboard!
You must configure a pull secret for peer pods. Then, you can link the pull secret to the default service account or you can specify the pull secret in the peer pod manifest.
Procedure
Set the
NSvariable to the namespace where you deploy your peer pods:$ NS=<namespace>Copy the pull secret to the peer pod namespace:
$ oc get secret pull-secret -n openshift-config -o yaml \ | sed "s/namespace: openshift-config/namespace: ${NS}/" \ | oc apply -n "${NS}" -f -You can use the cluster pull secret, as in this example, or a custom pull secret.
Optional: Link the pull secret to the default service account:
$ oc secrets link default pull-secret --for=pull -n ${NS}
3.7. Selecting a custom peer pod VM image Copy linkLink copied to clipboard!
You can select a custom peer pod virtual machine (VM) image, tailored to your workload requirements, by adding an annotation to the pod manifest. The custom image overrides the default image specified in the peer pods config map.
Prerequisites
- If the custom peer pod VM image is in a private registry, you have created a pull secret.
- You have the ID of a custom pod VM image, which is compatible with your cloud provider or hypervisor.
Procedure
Create a
my-pod-manifest.yamlfile according to the following example:apiVersion: v1 kind: Pod metadata: name: my-pod-manifest annotations: io.katacontainers.config.hypervisor.image: "<custom_image_id>" spec: runtimeClassName: kata-remote containers: - name: <example_container> image: registry.access.redhat.com/ubi9/ubi:9.3 command: ["sleep", "36000"]Create the pod by running the following command:
$ oc create -f my-pod-manifest.yaml
3.8. Configuring your workload Copy linkLink copied to clipboard!
You configure your workload for OpenShift sandboxed containers by setting kata-remote as the runtime class for the following pod-templated objects:
-
Podobjects -
ReplicaSetobjects -
ReplicationControllerobjects -
StatefulSetobjects -
Deploymentobjects -
DeploymentConfigobjects
Do not deploy workloads in an Operator namespace. Create a dedicated namespace for these resources.
You can define whether the workload should be deployed using the default instance type, which you defined in the peer pods config map, by adding an annotation to the YAML file.
If you do not want to define the instance type manually, you can add an annotation to use an automatic instance type, based on the memory available.
Prerequisites
-
You have created the
KataConfigcustom resource (CR).
Procedure
Add
spec.runtimeClassName: kata-remoteto the manifest of each pod-templated workload object as in the following example:apiVersion: v1 kind: <object> # ... spec: runtimeClassName: kata-remote # ...Optional: To override the default instance type, add the following annotation with an instance type that is defined in the peer pods config map:
apiVersion: v1 kind: <object> metadata: annotations: io.katacontainers.config.hypervisor.machine_type: <instance> # ...Optional: To use an automatic instance type, add the following annotations:
apiVersion: v1 kind: <Pod> metadata: annotations: io.katacontainers.config.hypervisor.default_vcpus: <vcpus> io.katacontainers.config.hypervisor.default_memory: <memory> # ...The workload will run on an automatic instance type based on the amount of memory available.
Apply the changes to the workload object by running the following command:
$ oc apply -f <object.yaml>OpenShift Container Platform creates the workload object and begins scheduling it.
Verification
-
Inspect the
spec.runtimeClassNamefield of a pod-templated object. If the value iskata-remote, then the workload is running on OpenShift sandboxed containers.