Hello Readers! Welcome back to Day 58 of our #90DaysOfDevOps series. Today, we will be deploying our first application to a local Kubernetes cluster.
Deploying Your First Application: A Step-by-Step Guide
Understanding Kubernetes Deployment Resource:
In Kubernetes, a Deployment is a resource object in the cluster that provides declarative updates to applications. It allows you to describe an application’s lifecycle, such as which images to use for the app, the number of pod replicas, and the way to update them.
Creating a Simple Kubernetes Deployment:
Here's a basic example of a Kubernetes Deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-first-app
spec:
replicas: 3
selector:
matchLabels:
app: my-first-app
template:
metadata:
labels:
app: my-first-app
spec:
containers:
- name: my-first-app-container
image: nginx:latest
In this example:
replicas: 3 specifies that we want three replicas (or instances) of our application running.
selector is used to match the pods controlled by this deployment.
template is the blueprint for creating pods. It includes metadata labels and the container spec.
Deploying the Application:
1. Save the above manifest in a file, e.g., first-app-deployment.yaml.
2. Deploy the application using the kubectl apply command:
kubectl apply -f first-app-deployment.yaml
3. Check the status of your deployment:
kubectl get deployments
4. Verify that pods are running:
kubectl get pods
Exploring Your Deployed Application:
Now that your application is deployed, you can access it via the exposed service or directly through the pods. If using a service, find the service's external IP and access it in your web browser.
Understanding Replication Controllers:
Behind the scenes, the Deployment controller manages ReplicaSets, and ReplicaSets manage the actual pods. This abstraction allows for easy scaling, rolling updates, and rollbacks.
Why This Matters:
Scalability: Deployments make it easy to scale your applications by adjusting the replicas field.
Rolling Updates: Deployments support rolling updates, enabling seamless transitions to new versions without downtime.
Declarative Configuration: Describe your desired state, and Kubernetes takes care of reaching and maintaining that state.
By successfully deploying your first application, you've entered the realm of practical Kubernetes usage. Congratulations on this milestone!
Thank you for joining us on Day 58 of #90DaysOfDevOps.
*** Explore | Share | Grow ***
Comments