replicaset doc

This commit is contained in:
2024-07-15 23:03:44 +03:30
parent 24df655dc0
commit c5fc73e396
3 changed files with 113 additions and 4 deletions

View File

@@ -114,4 +114,23 @@ This command retrieves and displays the YAML configuration of the pod `testpod1`
kubectl label node <node-name> kubernetes.io/<var-name>=<var-value> kubectl label node <node-name> kubernetes.io/<var-name>=<var-value>
kubectl get nodes --show-labels 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
```

View File

@@ -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 ## Namespace Definition
```yaml ```yaml

View File

@@ -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
```