- Take me to Video Tutorial
In this section, we will take a look at the below
- Replication Controller
- ReplicaSet
Replication Controller
is the older technology that is being replaced by aReplicaSet
.ReplicaSet
is the new way to setup replication.
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
- To Create the replication controller
$ kubectl create -f rc-definition.yaml
- To list all the replication controllers
$ kubectl get replicationcontroller
- To list pods that are launch by the replication controller
$ kubectl get pods
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
-
To Create the replicaset
$ kubectl create -f replicaset-definition.yaml
-
To list all the replicaset
$ kubectl get replicaset
-
To list pods that are launch by the replicaset
$ kubectl get pods
- There are multiple ways to scale replicaset
- First way is to update the number of replicas in the replicaset-definition.yaml definition file. E.g replicas: 6 and then run
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 6
selector:
matchLabels:
type: front-end
$ kubectl apply -f replicaset-definition.yaml
- Second way is to use
kubectl scale
command.
$ kubectl scale --replicas=6 -f replicaset-definition.yaml
- Third way is to use
kubectl scale
command with type and name
$ kubectl scale --replicas=6 replicaset myapp-replicaset