You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Pod's section you’ve learned that, pods represent the basic deployable unit in Kubernetes.
We have seen how to create, supervise, and manage them manually.
We've also seen the challenges while launching application in pods and managing applications with ONLY pods.
So, in the real-world use cases, you want your deployments to stay up and running automatically and remain healthy without any manual intervention.
To do this, you almost never create pods directly. Instead, you create other types of resources, such as ReplicationControllers or Deployments, which then create and manage the actual pods.
What is ReplicationControllers
A ReplicationController is a Kubernetes resource that ensures its pods are always kept running.
If the pod disappears for any reason, such as in the event of a node disappearing from the cluster or because the pod was evicted from the node, the ReplicationController notices the missing pod and creates a replacement pod.
Creating a Simple ReplicaSet with nginx Containersvi replicaset-nginx.yamlapiVersion: apps/v1kind: ReplicaSetmetadata:
name: nginx-replicasetlabels:
app: nginxspec:
replicas: 2selector:
matchLabels:
environment: productiontemplate:
metadata:
labels:
environment: productionspec:
containers:
- name: nginx-containerimage: nginxkubectl create -f replicaset-nginx.yamlkubectl get rs nginx-replicasetkubectl get podskubectl describe rs nginx-replicaset
Deleting Pods Managed by a ReplicaSet======================================kubectl get podskubectl delete pod <pod_name>kubectl describe rs nginx-replicasetkubectl delete rs nginx-replicasetkubectl get pods
Scaling a ReplicaSet
===========================================
vi replicaset-nginx.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
environment: production
template:
metadata:
labels:
environment: production
spec:
containers:
- name: nginx-container
image: nginx
kubectl apply -f replicaset-nginx.yaml
kubectl get pods
kubectl scale --replicas=4 rs nginx-replicaset
kubectl get pods
kubectl scale --replicas=1 rs nginx-replicaset
kubectl get pods
kubectl delete rs nginx-replicaset