Kubernetes Deployment Yaml Example
Kubernetes Deployment Yaml Example
To deploy containerized applications in Kubernetes cluster we use Kubernetes Deployment. We can create and manage a Deployment by using the Kubernetes Deployment Yaml file. We can define entire deployment object in a single yml file. This object is responsible for creating the pods, and ensuring there are running.
Kubernetes Deployment Yaml Example
cat abcd.yml
apiVersion: apps/v1 kind: Deployment metadata: name: mydep labels: dep: nginxdep spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.16.1 ports: - containerPort: 80
Kubernetes deployment Yaml contains the following main specifications.
- apiVersion
- Kind
- metadata
- spec
- template
apiVersion
apiVersion specifies the API version of the Kubernetes deployment object.
kind
Kind describes the type of the object/resource to be created.
metadata
In metadata we can assign name and labels to deployment object.
spec
Spec represents which pods this deployment should take care. So the deployment will identify the pods using labels in selector. And we can mention number of pods should run always using replicas.
template
When the deployment creates pods, it will create them using this template.
Create the deployment using kubectl
using kubectl create command we can create deployment
syntax
kubectl create -f <yml filename>
kubectl create -f abcd.yaml
List the Deployments
using kubectl get command we can list the deployments.
master $ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE mydep 3/3 3 3 12s
Get More Inforamtion about Deployment.
using kubectl describe command we can get more information about deployment.
Syntax:
kubectl describe deployments <deployment name>
master $ kubectl describe deployments mydep Name: mydep Namespace: default CreationTimestamp: Sat, 07 Sep 2019 14:31:49 +0000 Labels: dep=nginxdep Annotations: deployment.kubernetes.io/revision: 1 kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"nginx"},"name":"mydep","namespace":"default"},"s... Selector: app=nginx Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: app=nginx Containers: nginx: Image: nginx:1.16.1 Port: 80/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: <none> NewReplicaSet: mydep-59777878f8 (3/3 replicas created) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 3m12s deployment-controller Scaled up replica set mydep-59777878f8 to 3
Here you can see whatever we defined in yml we can see that information. And also we can see number of pods created and available.
- Kubernetes Deployment Yaml example
- Kubernetes Yaml Deployment example
- kubernetes deployment yaml reference