Red Hat Certified Engineer RHCE · Free Practice Question Medium
Question 9
You are tasked with automating the deployment and management of Kubernetes clusters using an Ansible Content Collection. This collection includes roles specifically designed for managing Kubernetes. How would you install the Content Collection and use its roles to configure and manage Kubernetes clusters effectively?
-
A
- # Install the Kubernetes Content Collection
- ansible-galaxy collection install kubernetes.core
- # Use the roles to manage the Kubernetes cluster
- - hosts: k8s_nodes
- roles:
- - kubernetes.core.k8s_cluster
- tasks:
- - name: Deploy Kubernetes application
- kubernetes.core.k8s:
- definition: "{{ lookup('file', 'app.yaml') }}"
This process automates the deployment and management of Kubernetes clusters, leveraging the roles provided by the collection for efficiency and consistency.
-
B
This is a performance based question and not multiple choice. Therefore the answer is in #1. If you require additional explanation, please ask your question in the Q&A section.
Reveal correct answer
Correct answer: A
A.
In this solution, the Ansible Content Collection for Kubernetes is used to automate the deployment and management of Kubernetes clusters. First, the kubernetes.core collection is installed using the ansible-galaxy command, which includes roles specifically designed for Kubernetes. The playbook then uses the kubernetes.core.k8s_cluster role to manage the Kubernetes cluster on nodes defined under the k8s_nodes group. A task within the playbook deploys a Kubernetes application using the kubernetes.core.k8s role, with the application's configuration loaded from a file using the lookup function. This structure leverages the built-in roles and modules within the Content Collection to manage Kubernetes clusters efficiently and consistently.
Line-by-Line Explanation
# Install the Kubernetes Content CollectionA comment indicating that the following command will install the
kubernetes.corecollection, which includes roles and modules for managing Kubernetes clusters.
ansible-galaxy collection install kubernetes.coreThis command installs the
kubernetes.corecollection from Ansible Galaxy, which contains roles and modules for managing Kubernetes environments.
# Use the roles to manage the Kubernetes clusterA comment indicating that the next section will use roles to manage the Kubernetes cluster.
- hosts: k8s_nodesSpecifies that the tasks will be executed on hosts in the
k8s_nodesgroup, which is likely defined in the inventory and consists of the nodes in the Kubernetes cluster.
roles:Introduces the list of roles to be used in the playbook. In this case, the roles manage the Kubernetes cluster and related configurations.
- kubernetes.core.k8s_clusterSpecifies the
k8s_clusterrole from thekubernetes.corecollection. This role is used to manage the Kubernetes cluster.
tasks:Introduces the tasks to be executed as part of the playbook.
- name: Deploy Kubernetes applicationThis task is named "Deploy Kubernetes application" and will deploy an application to the Kubernetes cluster.
kubernetes.core.k8s:This task uses the
k8smodule from thekubernetes.corecollection to manage Kubernetes resources.
definition: "{{ lookup('file', 'app.yaml') }}"The
lookupfunction retrieves the contents of theapp.yamlfile, which contains the configuration for the Kubernetes application. Thedefinitionparameter then passes this configuration to thek8smodule to deploy the application.
This playbook and structure automate the deployment and management of Kubernetes clusters by utilizing roles from the kubernetes.core collection, ensuring efficient and consistent management of cluster resources. The use of the lookup function to load application configurations allows for flexibility and dynamic management of the deployment.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
