Replication Controller
it helps to run multiple instances of a single part in the Kubernetes cluster, to ensure the application is always available.
If we have a single pod, the replication controller can help by automatically bringing up a new pod when the existing one fails.
When the demand increases we deploy additional pods in the node. but if we were to run out of the resource on the first node, we could deploy the additional pods on other nodes in the cluster. So, It also helps us balance the load across multiple parts on different nodes as scale the application when the demand increases.
How to use the replication controller?
Example: I created a YAML file: rc-defination.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 3
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
apiVersion and kind please refer to the post: Kubernetes Pods, YAML
In spec, I defined a template it's used to create the pod and replicas mean how many pods we will create.
The template is following the YAML file formation
kubectl create -f rc-defination.yml
kubectl get replicationcontroller
Replica Set
The replica set is a new technology, it has been recommended way to set up replication. It replaces the replication controller.
The properties in ReplicaSet:
apiVersion: apps/v1
kind: Replicaset
metadata:
spec:
template:
recplicas: 2
selector:
In replica set is required for sector property, it is optional in the replication controller.
The selector section helps the replica set identify what parts fall under it as long as it matched to selectors.
Example
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
The command to create it's the same as the replication controller.
Replica Set and Replication Controller
Scale and Commands
kubectl scale rs new-replica-set --replicas=5
kubectl create -f replicaset-definition.yml
kubectl get replicaset
kubectl delete replicaset my-replica
To replace
kubectl repleace -f replicaset-definition.yml
To edit
kubectl edit replicaset [name of replica set]
Deployment?
[From google document] Deployments represent a set of multiple, identical Pods with no unique identities. A Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive. In this way, Deployments help ensure that one or more instances of your application are available to serve user requests. Deployments are managed by the Kubernetes Deployment controller.
It's similar as create a replica set, when we create the YAML file, we replace kind: ReplicaSet => kind: Deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Then create a deployment we run the command below:
kubectl create -f deployment-definition.yml
Documentations:
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
https://cloud.google.com/kubernetes-engine/docs/concepts/deployment
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#rollout
More keywords: Services, Network, ClusterIP, Deployment, Update, Rollout, Rollback.