Git Product home page Git Product logo

k8s_intro's Introduction

Application Deployment using Kubernetes

This guide will help you deploy a Node.js API and Redis cache using Kubernetes (K8s).

Prerequisites

  • Docker installed on your local machine.
  • Kubernetes (K8s) cluster set up.

Steps

1. Build and Push Docker Images

API Image

  1. Build the Docker image for the API:
docker build -t <your-registry>/api:v1 .
  1. Push the API image to your local Docker registry:
docker push <your-registry>/api:v1

Redis Image

  1. Build the Docker image for Redis cache:
docker build -t <your-registry>/redis:v1 .
  1. Push the Redis image to your local Docker registry:
docker push <your-registry>/redis:v1

2. Deploy API and Redis to Kubernetes

API Deployment

  1. Create a deployment YAML file named api-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: <your-registry>/api:v1
          ports:
            - containerPort: 1337
  1. Apply the API deployment to the Kubernetes cluster:
kubectl apply -f api-deployment.yaml

Redis Deployment

1.Create a deployment YAML file named redis-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
        - name: redis
          image: <your-registry>/redis:v1
          ports:
            - containerPort: 6379
  1. Apply the Redis deployment to the Kubernetes cluster:
kubectl apply -f redis-deployment.yaml

3. Expose the API Service using NGINX Ingress

  1. Create a service YAML file named api-service.yaml:
apiVersion: v1
kind: Service
metadata:
  name: api-service
spec:
  selector:
    app: api
  ports:
    - protocol: TCP
      port: 80
      targetPort: 1337
  1. Create an Ingress YAML file named api-ingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api-ingress
spec:
  rules:
    - host: <your-api-domain.com>
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80
  1. Apply the API Ingress resource to define the routing rules:
kubectl apply -f api-ingress.yaml

4. Verify Deployment

  1. Check the status of the API and Redis deployments:
kubectl get deployments
  1. Verify that the API and Redis pods are running:
kubectl get pods
  1. Check the status of the Ingress resource:
kubectl get ingress

k8s_intro's People

Contributors

globecitizen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.