kubernetes-training

Replica

Replication Controller Replica Set
   

Create a replica controller

apiVersion: v1 
kind: ReplicationController
metadata:
	name: myapp-rc
	type: frontend

spec: 
	template:
		metadata:
			name: myapp-pod
			labels: 
				app:myapp
		spec: 
			containers:
			- name: nginx-container
			  image: nginx 
	replicas: 3
		

Create a replica set

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
	
	

Note: matchLabels under selector have to match with labels of the pod template

To get the replica: kubectl get replicaset or kubectl get rs

Labels and Selectors

Scale

  1. To apply new changes from the newly updated yaml file kubectl replace -f replicaset-definition.yaml
  2. From command line : this won’t modify the file directly kubectl scale --replicas=6 -f replicaset-definition.yaml
  3. type- name kubectl scale --replicas=6 replicaset myapp-replicaset
  4. to edit kubectl edit rs myapp-replicaset

Commands

References

https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#replicaset-as-an- horizontal-pod-autoscaler-target