lables,selector,replicaset,deploymentset
Labels:-
Labels are the mechanism to organize Kubernetes objects such as Pods
A label is a key-value pair.
Labels can be attached to objects at creation time or added and modified at any time.
"metadata": {
"labels": {
"key1" : "value1",
"key2" : "value2"
}
}
To create lables imperative we can use
kubectl label pods delhipod myname=ajay // delhipod is pod name
to check the lables
kubectl get pods --show-labels // to show the lables of pods
To get the pods where env is not equal to development
kubectl get pods -l env!=development // We need to use ! sign before key (env is key hear)
We can also delete the pods using lables
kubectl delete pod -l env!=development
Labels Selector
Once the lables are attached to an object, we would need filters to narrow down and these are called as labels selector
The API currently supports two types of selector -
1 equality based ( =, !=) equal to or not equal to.
example name=ajay
2 Set based : ( in, notin or exists)
env in (production, dev)
env notin (team1 , team2)
Kuberntes also supports setbased slectors ie match multiple values.
Replication controller :-
Replication Controller is one of the key features of Kubernetes, which is responsible for managing the pod lifecycle. It is responsible for making sure that the specified number of pod replicas are running at any point of time. It is used in time when one wants to make sure that the specified number of pod or at least one pod is running. It has the capability to bring up or down the specified no of pod.
It is a best practice to use the replication controller to manage the pod life cycle rather than creating a pod again and again.
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 3
selector:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Replication Set :-
Replica Set ensures how many replica of pod should be running. It can be considered as a replacement of replication controller. The key difference between the replica set and the replication controller is, the replication controller only supports equality-based selector whereas the replica set supports set-based selector.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
Difference between rc and rs
Replication Controller
Replica Set
The Replication Controller is the original form of replication in Kubernetes
ReplicaSets are a higher-level API that gives the ability to easily run multiple instances of a given pod
The Replication Controller uses equality-based selectors to manage the pods.
ReplicaSets Controller uses set-based selectors to manage the pods.
The rolling-update command works with Replication Controllers
The rolling-update command won’t work with ReplicaSets.
Replica Controller is deprecated and replaced by ReplicaSets.
Deployments are recommended over ReplicaSets.
Deployment
Comments
Post a Comment