Professional Documents
Culture Documents
This actually means that you may never need to manipulate ReplicaSet objects:
use directly a Deployment and de ne your application in the spec section.
Replica Sets are a sort of hybrid, in that they are in some ways more powerful
than Replication Controllers, and in others they are less powerful.
Replica Sets are declared in essentially the same way as Replication Controllers,
except that they have more options for the selector. For example, we could
create a Replica Set like this:
File: rs.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-test
namespace: <yourname>
spec:
replicas: 3
selector:
matchLabels:
app: test-rs
template:
metadata:
labels:
app: test-rs
environment: dev
spec:
containers:
- name: container01
image: nginx
ports:
- containerPort: 80
In this case, it’s more or less the same as when we were creating the Replication
Controller, except we’re using matchLabels instead of label. But we could just as
easily have said:
...
spec:
replicas: 3
selector:
matchExpressions:
- {key: app, operator: In, values: [test-rs, qa-rs, prd-rs]}
- {key: environment, operator: NotIn, values: [prd]}
template:
metadata:
...
In this case, we’re looking at two different conditions:
The app label must be test-rs, qa-rs, or prd-rs The tier label (if it exists) must not
be production
You can also see that the apiVersion are no more core. for determine the correct
apiVersion run:
replicasets rs apps
true ReplicaSet
replicasets rs extensions
true ReplicaSet
We will use apiVersion apps apps belongs to v1, the stable version, so you will
write apps/v1 Check it using kubectl api-versions command
apps/v1
Let’s go ahead and create the Replica Set and get a look at it:
replicaset.apps/replicaset-test created
Describe ReplicaSet
student@master:~$ kubectl describe -n <yourname> rs replicaset-test
Name: replicaset-test
Namespace: default
Selector: app=test-rs
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"ReplicaSet","metadata":
{"annotations":{},"name":"replicaset-
test","namespace":"default"},"spec":{"replicas...
Replicas: 3 current / 3 desired
Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=test-rs
environment=dev
Containers:
container01:
Image: nginx
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Events: <none>
As you can see, the output is pretty much the same as for a Replication
Controller (except for the selector), and for most intents and purposes, they are
similar. The major difference is that the rolling-update command works with
Replication Controllers, but won’t work with a Replica Set. This is because
Replica Sets are meant to be used as the backend for Deployments.
Again, the pods that were created are deleted when we delete the Replica Set.
No resources found.