Kubernetes : Pod Communications, Deployments and ReplicaSets
Pod Communications
Here, in the above diagram, you can see two pods -
- Pod A (IP - 10.0.1.16) with two containers - Con1 ( port - 8000) and Con2 ( port - 6000 ).
- Pod B (IP - 10.2.2.100) with container - Con1 ( port - 8087).
Inter Pod Communication
Intra Pod Communication
Usage of Multi-Container pods
- Sidecar Containers - They assist the main application container. Log watcher and shippers, monitoring agents, etc. are typical Sidecar containers.
- Bridges, Adapters, Proxies - They connect the main container with the outside world. Examples - Apache HTTP server, NodeJS server, Nginx server, etc.
Deployments and ReplicaSet
Deployment and ReplicaSet are used to manage and run specific configuration related to Pod. Lets discuss in details.
Deployment
As per Kubernetes documentation,
"A Deployment provides declarative updates for Pods and ReplicaSets."
What does it actually mean ?
Well, Deployment is a way of deploying a pod or sets of identical pods ( ReplicaSets ) where their desired states are mentioned in a configuration/manifest file. The Deployment Controller, that resides inside Control Plane, takes control and tries to change from actual state to the desired state in a controlled fashion and tries to maintain it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Once we execute - kubectl apply -f deployment.yaml
There will be a set of 3 pods created with each containing an nginx container exposed at port 80. If a pod dies or get deleted accidently, the Deployment Controller will bring up another pod to maintain the total number of pods as 3. You can also achieve this with ReplicaSet object.
ReplicaSet
A ReplicaSet ensures that a specified number of pod replicas are running at any given time. However, a Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features.
Let us consider the below ReplicaSet manifest file named rs.yaml -
apiVersion: apps/v1kind: ReplicaSetmetadata:name: frontendlabels:app: guestbooktier: frontendspec:# modify replicas according to your casereplicas: 3selector:matchLabels:tier: frontendtemplate:metadata:labels:tier: frontendspec:containers:- name: php-redisimage: gcr.io/google_samples/gb-frontend:v3
Once we execute - kubectl apply -f rs.yaml , a set of 3 pods with single containers in each is created.
Therefore, a ReplicaSet, like Deployment, ensures that a specified number of pod replicas are running at any given time. However, a Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features. Hence, Deployment is preffered over ReplicaSet.
I would be concluding this blog over here, will continue my discussion on Kubernetes components in further blogs.
Comments
Post a Comment