Reputation: 2728
I have two kind: Deployment
in my yaml
file
The main one
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounts-management-service
labels:
app: accounts-management-service
spec:
replicas: $($env:WEB_REPLICAS)
selector:
matchLabels:
app: accounts-management-service
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 20%
maxUnavailable: 10%
progressDeadlineSeconds: 3600
template:
metadata:
labels:
app: accounts-management-service
spec:
containers:
- image: registry$(GetHash).azurecr.io/$(GetContext 'ApplicationContainerName')
name: accounts-management-service
command: ["npm"]
args: ["run", "start:production:web"]
resources:
requests:
memory: "500Mi"
cpu: "1000m"
limits:
memory: "4096Mi"
cpu: "1001m"
env:
- name: CONFIG_DEPLOYMENT_UNIT
value: $(GetContext 'DeploymentUnit')
- name: NODE_ENV
value: $(GetContext 'DeploymentUnit')
- name: TENANT
value: "$(GetContext 'DeploymentUnit' | Format -NoHyphens)$(GetContext 'Cluster')"
- name: ROLE
value: $(GetContext 'Cluster')
ports:
- containerPort: 1337
protocol: TCP
volumeMounts:
- name: secret-agent
mountPath: /var/run/secret-agent
readinessProbe:
httpGet:
path: /v0.1/status
port: 1337
successThreshold: 2
failureThreshold: 3
initialDelaySeconds: 60
periodSeconds: 10
livenessProbe:
httpGet:
path: /v0.1/status_without_db
port: 1337
failureThreshold: 3
initialDelaySeconds: 60
periodSeconds: 30
volumes:
- name: secret-agent
hostPath:
path: /var/run/secret-agent
type: DirectoryOrCreate
and the second one
# second
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounts-management-service-second
labels:
app: accounts-management-service-second
spec:
replicas: $($env:second_REPLICAS)
selector:
matchLabels:
app: accounts-management-service-second
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 10%
maxUnavailable: 10%
template:
metadata:
labels:
app: accounts-management-service-second
spec:
containers:
- image: registry$(GetHash).azurecr.io/$(GetContext 'ApplicationContainerName')
name: accounts-management-service-second
command: ["npm"]
args: ["run", "start:production:second"]
resources:
requests:
memory: "500Mi"
cpu: "250m"
limits:
memory: "8192Mi"
cpu: "1001m"
env:
- name: CONFIG_DEPLOYMENT_UNIT
value: $(GetContext 'DeploymentUnit')
- name: NODE_ENV
value: $(GetContext 'DeploymentUnit')
- name: TENANT
value: "$(GetContext 'DeploymentUnit' | Format -NoHyphens)$(GetContext 'Cluster')"
- name: ROLE
value: $(GetContext 'Cluster')
ports:
- containerPort: 1337
protocol: TCP
volumeMounts:
- name: secret-agent
mountPath: /var/run/secret-agent
readinessProbe:
httpGet:
path: /status
port: 1337
initialDelaySeconds: 60
periodSeconds: 10
livenessProbe:
httpGet:
path: /status
port: 1337
initialDelaySeconds: 60
periodSeconds: 10
volumes:
- name: secret-agent
hostPath:
path: /var/run/secret-agent
type: DirectoryOrCreate
They both point to the same volume path. I am new to Kubernetes and I am trying to understand the relation between pod creation and two kind: Deployment
s. It would be nice if someone can explain thos. I hope that this falls into the SO allowed questions category.
Upvotes: 1
Views: 220
Reputation: 30093
Deployment manage the replicas count basically for any workload configured.
Deployment in the background uses the Replicasets
or ReplicationController
.
So if in deployment you have the desired replica 1 it will get managed by deployment.
Deployment continuously checks for the desired replicas and scalable replicas if scaling is in place.
It's suggested to implement the scaling above the deployment and scaling HPA will inform to deployment for scaling the replicas to 3-4
etc.
You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
Also in deployment, you configure the policy for an update if you are updating the PODs or container so ideally one by one they go down and a new ones come.
So less downtime occurred during the process, this policy managed and configurable at deployment level.
Example
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 20%
maxUnavailable: 10%
also, two deployments mean there two different types of applications or microservice is configured or workloads in YAML. One for each micro service configuration.
Feel free to add questions in a comment if you have any.
Upvotes: 0
Reputation: 96
If you want to figure out which pods were created by specified deployment, you could use kubectl get pods
command with --selector
option to filter these pods.
The labels you defined in deployment templates were app=accounts-management-service
and app=accounts-management-service-second
, you could figure out these pods by:
$ kubectl get pods --selector=app=accounts-management-service
$ kubectl get pods --selector=app=accounts-management-service-second
Upvotes: 1
Reputation: 1918
Basically Deployments find out which pods they are managing by labels defined in the deployments spec section as well as under .spec.template.spec section.
Deployments check for running pods that match the supplied labels while figuring out whether the available replica count is the desired replica count.
If desired count > available count the DeploymentController creates a new pod based on the template section (actually, the deployment controls a ReplicaSet which in turn controls the pods, but this is additional knowledge not really needed for your understanding). However, deployments do not only create and delete pods based on the template. If there are already pods running in the namespace the deployment is on which matches the labels specified in your deployment, it will count this pod as being part of your deployment and towards the available replicas.
Hope this clarifies your understanding of deployments a bit.
Upvotes: 1