Kubernetes, the container-orchestration system, is pivotal in deploying scalable cloud applications effectively. By the end of this post, developers will have a clear understanding of how to put Kubernetes in Action by running applications that can scale on demand and are resilient.
Table of Contents
Kubernetes offers the ability to orchestrate and manage containers at scale, providing features such as automated deployments, rollbacks, scaling and self-healing of applications. For cloud applications, where demand can fluctuate, Kubernetes ensures that your application can adapt without manual intervention.
Getting Started with Kubernetes
To begin with Kubernetes, you need to understand Pods, Deployment, and Services – key resources that you’ll define using YAML or JSON configuration files. A Pod is the smallest deployable unit in Kubernetes, whereas a Deployment manages the Pods. Finally, a Service defines the policies for accessing the Pods.
Deploying Your First App
We take the example of deploying a simple HTTP web server. We first create a Deployment object:
apiVersion: apps/v1 kind: Deployment metadata: name: webserver-deployment spec: replicas: 2 selector: matchLabels: app: webserver template: metadata: labels: app: webserver spec: containers: - name: webserver image: nginx:1.14.2 ports: - containerPort: 80
This code creates a Deployment named “webserver-deployment” with 2 replicas – meaning it runs two instances of the webserver.
Scaling Your Application
When the load increases, you may need more instances. To scale your Deployment, you would update the “replicas”:
spec: replicas: 5
Or, use the kubectl command line:
kubectl scale deployment/webserver-deployment --replicas=5
Updating Your Application
Let’s say you need to update the nginx image to a newer version. Modify the Deployment’s image:
spec: template: spec: containers: - name: webserver image: nginx:1.16.1
… or use kubectl to update directly:
kubectl set image deployment/webserver-deployment webserver=nginx:1.16.1
Using the kubectl command line to get the status of your deployments might give you the following output:
NAME READY UP-TO-DATE AVAILABLE AGE webserver-deployment 5/5 5 5 10m
Output: This shows that all five replicas of the deployment are up and running.
In summary, Kubernetes in Action means deploying, scaling, and updating applications in a cloud environment efficiently and with minimal downtime. By leveraging Kubernetes, you enable your applications to handle varying loads and automatically recover from potential failures.