This is in continuation of the Kubernetes article series. In the last post, we have learned how to create & deploy the app to the Kubernetes cluster. Now in this post, we are going to learn how to create application deployment using the YAML file, and also we can check how to create services to control the application communication.
Quick Snapshot
Using Deployment controller we can provide declarative updates for Pods and ReplicaSets. Create deployment.yaml file in your current folder like the below to describe the Nginx deployment.
Kubernetes manifest file defines a desired state for the cluster, including what container images should be running.For example, this YAML file describes a Deployment that runs the nginx:latest Docker image
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
In this example:
kubectl create -f deployment.yaml
When you inspect the Deployments in your cluster, the following fields are displayed:
NAME
lists the names of the Deployments in the cluster.DESIRED
displays the desired number of replicas of the application, which you define when you create the Deployment. This is the desired state.CURRENT
displays how many replicas are currently running.UP-TO-DATE
displays the number of replicas that have been updated to achieve the desired state.AVAILABLE
displays how many replicas of the application are available to your users.AGE
displays the amount of time that the application has been running.Kubernetes has powerful networking capabilities that control how applications communicate. These networking configurations can also be controlled via YAML. The Service selects all applications with the label nginx. As multiple replicas, or instances, are deployed, they will be automatically load balanced based on this common label. The Service makes the application available via a NodePort.
Kubernetes Service
is an abstraction which defines a logical set of Pods
and a policy by which to access them (micro-service). The set of Pods
targeted by a Service
is determined by a Label Selector
apiVersion: v1 kind: Service metadata: name: nginx-svc labels: app: nginx spec: type: NodePort ports: - port: 80 nodePort: 30080 selector: app: nginx
Use curl command to Issuing requests to the port 30080
Modify deployment.yaml to update the nginx deployment to have 4 replicas.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 4
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
kubectl apply -f deployment.yaml
When you inspect the Deployments in your cluster, the following fields are displayed:
NAME
lists the names of the Deployments in the cluster.DESIRED
displays the desired number of replicas of the application, which you define when you create the Deployment. This is the desired state.CURRENT
displays how many replicas are currently running.UP-TO-DATE
displays the number of replicas that have been updated to achieve the desired state.AVAILABLE
displays how many replicas of the application are available to your users.AGE
displays the amount of time that the application has been running.As all the Pods have the sameselector, they’ll be load balanced behind the Service NodePort deployed. Issuing requests to the port will result in different containers processing the request.
Congrats! we have learned how to create application deployment using the YAML file and also how to create services to control how application communicates.
Like this post? Don’t forget to share it!
There are few things as valuable to a business as well-designed software. Organizations today rely…
The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…
Introduction Artificial Intelligence (AI) has also found its relevance in graphic design and is quickly…
Imagine a world where the brilliance of Artificial Intelligence (AI) meets the unbreakable security of…
In today’s fast-paced digital landscape, automation is not just a luxury but a necessity for…
The world of casino gaming has leveraged the emerging technology advancements to create immersive and…
This website uses cookies.