From c5fc73e396a01295d11dc777e41b9a13b5d0fbb7 Mon Sep 17 00:00:00 2001 From: RadinPirouz Date: Mon, 15 Jul 2024 23:03:44 +0330 Subject: [PATCH] replicaset doc --- kubernetes/commands.md | 19 ++++++ kubernetes/workloads/pod.md | 4 -- kubernetes/workloads/replicaset.md | 94 ++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 kubernetes/workloads/replicaset.md diff --git a/kubernetes/commands.md b/kubernetes/commands.md index d998d42..2a8089d 100644 --- a/kubernetes/commands.md +++ b/kubernetes/commands.md @@ -114,4 +114,23 @@ This command retrieves and displays the YAML configuration of the pod `testpod1` kubectl label node kubernetes.io/= kubectl get nodes --show-labels ``` +### Retrieve the ReplicaSet +To retrieve information about the ReplicaSet in the `my-ns` namespace, use the following command: +```bash +kubectl get rs -n my-ns +``` + +### Delete All Pods in the Namespace +To delete all pods in the `my-ns` namespace, use the following command: +```bash +kubectl delete pod --all -n my-ns +``` + +### Change the Replica Count to 5 +To scale the ReplicaSet to 5 replicas, you can use one of the following methods: + +1. **Using the `kubectl scale` Command** +```bash +kubectl scale rs my-app --replicas=5 -n my-ns +``` diff --git a/kubernetes/workloads/pod.md b/kubernetes/workloads/pod.md index 9b92aff..e470bb4 100644 --- a/kubernetes/workloads/pod.md +++ b/kubernetes/workloads/pod.md @@ -1,7 +1,3 @@ -# Kubernetes YAML Files - -This document provides explanations and details for various Kubernetes YAML configurations, describing how different Kubernetes objects such as Namespaces, Pods, and other specifications are defined and utilized. The examples cover creating namespaces, deploying pods, setting resource limits, and using node selectors. - ## Namespace Definition ```yaml diff --git a/kubernetes/workloads/replicaset.md b/kubernetes/workloads/replicaset.md new file mode 100644 index 0000000..a51ff7d --- /dev/null +++ b/kubernetes/workloads/replicaset.md @@ -0,0 +1,94 @@ +## Document: Kubernetes ReplicaSet YAML Explanation + +### Overview +This document provides an explanation of a Kubernetes ReplicaSet YAML file and commands to manage the ReplicaSet. The YAML file defines the desired state for a ReplicaSet, which ensures a specified number of pod replicas are running at any given time. + +### YAML File Breakdown + +#### 1. Define the ReplicaSet +The YAML file begins with the `apiVersion`, `kind`, and `metadata` fields, which specify the API version, the type of Kubernetes object, and metadata about the object, respectively. + +```yaml +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: my-app + namespace: my-ns + labels: + app.kubernetes.io/name: my-app + app.kubernetes.io/env: development +``` +- `apiVersion: apps/v1`: Specifies that this configuration uses the `apps/v1` API version. +- `kind: ReplicaSet`: Defines the object as a ReplicaSet. +- `metadata`: Provides metadata for the ReplicaSet, including: + - `name`: The name of the ReplicaSet (`my-app`). + - `namespace`: The namespace where the ReplicaSet will be created (`my-ns`). + - `labels`: Key-value pairs to categorize the ReplicaSet (`app.kubernetes.io/name: my-app` and `app.kubernetes.io/env: development`). + +#### 2. Define the Specification +The `spec` section describes the desired state of the ReplicaSet. + +```yaml +spec: + replicas: 3 + selector: + matchLabels: + app.kubernetes.io/name: my-app + template: + metadata: + labels: + app.kubernetes.io/name: my-app + spec: + containers: + - name: nginx + image: nginx +``` +- `replicas: 3`: Specifies that three replicas of the pod should be running. +- `selector`: Defines how to identify the pods managed by this ReplicaSet. + - `matchLabels`: Matches pods with the label `app.kubernetes.io/name: my-app`. +- `template`: Provides the pod template used by the ReplicaSet to create new pods. + - `metadata`: Metadata for the pod template. + - `labels`: Labels applied to the pods (`app.kubernetes.io/name: my-app`). + - `spec`: Describes the pod specification. + - `containers`: Defines the containers within the pod. + - `name`: The name of the container (`nginx`). + - `image`: The container image to use (`nginx`). + + +### Update the Container Image Version + +To update the container image version, edit the YAML manifest and change the `image` field: +```yaml +containers: +- name: nginx + image: nginx:1.25 +``` +Apply the updated manifest to update the pods with the new image version. + +### Complete YAML File with Image Version Update + +Here is the complete YAML file with the container image version updated to `nginx:1.25`: + +```yaml +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: my-app + namespace: my-ns + labels: + app.kubernetes.io/name: my-app + app.kubernetes.io/env: development +spec: + replicas: 3 + selector: + matchLabels: + app.kubernetes.io/name: my-app + template: + metadata: + labels: + app.kubernetes.io/name: my-app + spec: + containers: + - name: nginx + image: nginx:1.25 +```