Kubernetes

Kubernetes: Deployments and Services

Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. It allows developers to manage containerized applications across a cluster of machines, providing essential features like scaling, load balancing, and automated rollouts and rollbacks.

Kubernetes Deployments

A Deployment in Kubernetes is a resource object that provides declarative updates to applications. You define the desired state of the application in a YAML file, and the Deployment controller makes the changes to the application’s current state to match the desired state. Deployments are used to create and manage a set of identical pods (containers running an application), ensuring that the specified number of replicas is always running.

Key Features of Deployments:

Kubernetes Services

A Service in Kubernetes is an abstract way to expose an application running on a set of Pods as a network service. With Kubernetes, you don’t need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

Types of Services:

YAML File Explanation

The provided YAML file defines a Kubernetes Deployment and a Service.

Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gpt-huggingface
spec:
  replicas: 3
  selector:
    matchLabels:
      app: gpt-hf-pod
  template:
    metadata:
      labels:
        app: gpt-hf-pod
    spec:
      containers:
      - name: gptcontainer
        image: image_name
        ports:
        - containerPort: 8000
apiVersion: v1
kind: Service
metadata:
  name: gpt-hf-service
spec:
  type: NodePort
  selector:
    app: gpt-hf-pod
  ports:
  - port: 8000 
    targetPort: 8000
    nodePort: 30007

Deploying the deploy.yaml File to Kubernetes

To deploy the deploy.yaml file to your Kubernetes cluster, follow these steps:

To deploy the deployment.yaml file, use the kubectl apply command:

kubectl apply -f deployment.yaml

This command will create the resources defined in the deploy.yaml file, such as the Deployment and Service.

Verify the Deployment

You can verify that your deployment was successful by checking the status of the deployment and services:

kubectl get deploy
kubectl get services

These commands will display the running deployments and services, confirming that your application is deployed and accessible.

Note: This is for illustration purposes. We are going to deploy this configuration using GitHub Actions, which will automate the deployment process as part of your CI/CD pipeline.

← Previous Next →