AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Assign Memory to Kubernetes Pods with Ansible — Video Tutorial

Learn how to assign memory resources to Kubernetes or OpenShift containers and pods using Ansible. Follow our live Playbook and simple code examples.

Watch on YouTube · Read the written article

Assign Memory to Kubernetes Pods with Ansible — Video Tutorial

Learn how to assign memory resources to Kubernetes or OpenShift containers and pods using Ansible. Follow our live Playbook and simple code examples.

Watch Video

Watch "Assign Memory to Kubernetes Pods with Ansible" on YouTube

What You'll Learn

Full Tutorial Content

How to Assign Memory Resources to Kubernetes K8s or OpenShift OCP Containers and Pods with Ansible? I’m going to show you a live Playbook and some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot. Containers cannot use more Memory than the configured limit. Provided the system has Memory time free, a container is guaranteed to be allocated as much Memory as it requests. To specify a Memory request for a container, include the `resources:requests` field in the Container resource manifest. To specify a Memory limit, include `resources:limits`. Ansible creates Kubernetes or OpenShift service - `kubernetes.core.k8s` - Manage Kubernetes (K8s) objects Let's talk about the Ansible module `k8s`. The full name is `kubernetes.core.k8s`, which means that is part of the collection of modules of Ansible to interact with Kubernetes and Red Hat OpenShift clusters. It manages Kubernetes (K8s) objects. Parameters - `name` _string_ /namespace _string_ - object name / namespace - `api_version` _string_ - "v1" - `kind` _string_ - object model - `state` _string_ - present/absent/patched - `definition` _string_ - YAML definition - `src` _path_ - path for YAML definition - `template` _raw_ - YAML template definition - `validate` _dictionary_ - validate resource definition There is a long list of parameters of the `k8s` module. Let me summarize the most used. Most of the parameters are very generic and allow you to combine them for many use-cases. The `name` and `namespace` specify object name and/or the object namespace. They are useful to create, delete, or discover an object without providing a full resource definition. The `api_version` parameter specifies the Kubernetes API version, the default is "v1" for version 1. The `kind` parameter specifies an object model. The `state` like for other modules determines if an object should be created - `present` option, patched - `patched` option, or deleted - `absent` option. The `definition` parameter allows you to provide a valid YAML definition (string, list, or dict) for an object when creating or updating. If you prefer to specify a file for the YAML definition, the `src` parameter provides a path to a file containing a valid YAML definition of an object or objects to be created or updated. You could also specify a YAML definition template with the `template` parameter. You might find useful also the `validate` parameter in order to define how to validate the resource definition against the Kubernetes schema. Please note that requires the `kubernetes-validate` python module. Links - [kubernetes.core.k8s](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html) - [Assign Memory Resources to Containers and Pods](https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/) - [polinux/stress image](https://hub.docker.com/r/polinux/stress) - [polinux/stress github](https://github.com/pozgo/docker-stress) Playbook How to Assign M

About This Tutorial

Read the full written article: Assign Memory to Kubernetes Pods with Ansible

Topics Covered

Related Video Tutorials