Lab 7.1
Lab 7.1
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
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
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.
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
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.
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.
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.