[go: up one dir, main page]

0% found this document useful (0 votes)
15 views3 pages

Lab 7.1

This document outlines a lab exercise focused on managing ReplicaSets in Kubernetes, detailing the creation, deletion, and manipulation of ReplicaSets and their associated Pods. It explains the use of YAML configuration files to define ReplicaSets and demonstrates how to view and manage Pods created by a ReplicaSet. Additionally, it covers isolating a Pod from its ReplicaSet and the behavior of ReplicaSets in maintaining the desired number of replicas.

Uploaded by

Pawan kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Lab 7.1

This document outlines a lab exercise focused on managing ReplicaSets in Kubernetes, detailing the creation, deletion, and manipulation of ReplicaSets and their associated Pods. It explains the use of YAML configuration files to define ReplicaSets and demonstrates how to view and manage Pods created by a ReplicaSet. Additionally, it covers isolating a Pod from its ReplicaSet and the behavior of ReplicaSets in maintaining the desired number of replicas.

Uploaded by

Pawan kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1

Exercise 7.1: Working with ReplicaSets

Overview
Understanding and managing the state of containers is a core Kubernetes task. In this lab we will first explore the API
objects used to manage groups of containers. The objects available have changed as Kubernetes has matured, so
the Kubernetes version in use will determine which are available. Our first object will be a ReplicaSet, which does
not include newer management features found with Deployments. A Deployment operator manages ReplicaSet
operators for you. We will also work with another object and watch loop called a DaemonSet which ensures a container
is running on newly added node.

Then we will update the software in a container, view the revision history, and roll-back to a previous version.

A ReplicaSet is a next-generation of a Replication Controller, which differs only in the selectors supported. The only
reason to use a ReplicaSet anymore is if you have no need for updating container software or require update orchestration
which won’t work with the typical process.

1. View any current ReplicaSets. If you deleted resources at the end of a previous lab, you should have none reported in
the default namespace.
student@lfs458-node-1a0a:˜$ kubectl get rs
No resources found in default namespace.

2. Create a YAML file for a simple ReplicaSet. The apiVersion setting depends on the version of Kubernetes you are
using. The object is stable using the apps/v1 apiVersion. We will use an older version of nginx then update to a newer
version later in the exercise.
student@lfs458-node-1a0a:˜$ vim rs.yaml

rs.yaml
1 apiVersion: apps/v1
2 kind: ReplicaSet
3 metadata:
4 name: rs-one
5 spec:
6 replicas: 2
7 selector:
8 matchLabels:
9 system: ReplicaOne
10 template:
11 metadata:
12 labels:
13 system: ReplicaOne
14 spec:
15 containers:
16 - name: nginx
17 image: nginx:1.15.1
18 ports:
19 - containerPort: 80

3. Create the ReplicaSet:

V 2020-04-20 © Copyright the Linux Foundation 2020. All rights reserved.


2 CHAPTER 7. MANAGING STATE WITH DEPLOYMENTS

student@lfs458-node-1a0a:˜$ kubectl create -f rs.yaml


replicaset.apps/rs-one created

4. View the newly created ReplicaSet:


student@lfs458-node-1a0a:˜$ kubectl describe rs rs-one
Name: rs-one
Namespace: default
Selector: system=ReplicaOne
Labels: system=ReplicaOne
Annotations: <none>
Replicas: 2 current / 2 desired
Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: system=ReplicaOne
Containers:
nginx:
Image: nginx:1.15.1
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Events: <none>

5. View the Pods created with the ReplicaSet. From the yaml file created there should be two Pods. You may see a
Completed busybox which will be cleared out eventually.
student@lfs458-node-1a0a:˜$ kubectl get pods
NAME READY STATUS RESTARTS AGE
rs-one-2p9x4 1/1 Running 0 5m4s
rs-one-3c6pb 1/1 Running 0 5m4s

6. Now we will delete the ReplicaSet, but not the Pods it controls.
student@lfs458-node-1a0a:˜$ kubectl delete rs rs-one --cascade=false
replicaset.apps "rs-one" deleted

7. View the ReplicaSet and Pods again:


student@lfs458-node-1a0a:˜$ kubectl describe rs rs-one
Error from server (NotFound): replicasets.apps "rs-one" not found

student@lfs458-node-1a0a:˜$ kubectl get pods


NAME READY STATUS RESTARTS AGE
rs-one-2p9x4 1/1 Running 0 7m
rs-one-3c6pb 1/1 Running 0 7m

8. Create the ReplicaSet again. As long as we do not change the selector field, the new ReplicaSet should take
ownership. Pod software versions cannot be updated this way.

student@lfs458-node-1a0a:˜$ kubectl create -f rs.yaml


replicaset.apps/rs-one created

9. View the age of the ReplicaSet and then the Pods within:
student@lfs458-node-1a0a:˜$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs-one 2 2 2 46s

V 2020-04-20 © Copyright the Linux Foundation 2020. All rights reserved.


3

student@lfs458-node-1a0a:˜$ kubectl get pods


NAME READY STATUS RESTARTS AGE
rs-one-2p9x4 1/1 Running 0 8m
rs-one-3c6pb 1/1 Running 0 8m

10. We will now isolate a Pod from its ReplicaSet. Begin by editing the label of a Pod. We will change the system:
parameter to be IsolatedPod.
student@lfs458-node-1a0a:˜$ kubectl edit pod rs-one-3c6pb

....
labels:
system: IsolatedPod #<-- Change from ReplicaOne
managedFields:
....

11. View the number of pods within the ReplicaSet. You should see two running.

student@lfs458-node-1a0a:˜$ kubectl get rs


NAME DESIRED CURRENT READY AGE
rs-one 2 2 2 4m

12. Now view the pods with the label key of system. You should note that there are three, with one being newer than others.
The ReplicaSet made sure to keep two replicas, replacing the Pod which was isolated.

student@lfs458-node-1a0a:˜$ kubectl get po -L system


NAME READY STATUS RESTARTS AGE SYSTEM
rs-one-3c6pb 1/1 Running 0 10m IsolatedPod
rs-one-2p9x4 1/1 Running 0 10m ReplicaOne
rs-one-dq5xd 1/1 Running 0 30s ReplicaOne

13. Delete the ReplicaSet, then view any remaining Pods.

student@lfs458-node-1a0a:˜$ kubectl delete rs rs-one


replicaset.apps "rs-one" deleted

student@lfs458-node-1a0a:˜$ kubectl get po


NAME READY STATUS RESTARTS AGE
rs-one-3c6pb 1/1 Running 0 14m
rs-one-dq5xd 0/1 Terminating 0 4m

14. In the above example the Pods had not finished termination. Wait for a bit and check again. There should be no
ReplicaSets, but one Pod.

student@lfs458-node-1a0a:˜$ kubectl get rs


No resources found in default namespaces.

student@lfs458-node-1a0a:˜$ kubectl get pod


NAME READY STATUS RESTARTS AGE
rs-one-3c6pb 1/1 Running 0 16m

15. Delete the remaining Pod using the label.

student@lfs458-node-1a0a:˜$ kubectl delete pod -l system=IsolatedPod


pod "rs-one-3c6pb" deleted

V 2020-04-20 © Copyright the Linux Foundation 2020. All rights reserved.

You might also like