Sobes.tech
Junior — Middle

What steps need to be taken to deploy and run an application inside a Kubernetes cluster?

sobes.tech AI

Answer from AI

To deploy and run an application in Kubernetes, follow these steps:

  1. Prepare the Docker image of the application:

    • Create a Dockerfile.
    • Build the image using docker build.
    • Push the image to a registry (Docker Hub, private registry, etc.).
  2. Create Kubernetes manifests:

    • Deployment — describes how to run pods with the application.
    • Service — for accessing the application inside or outside the cluster.
  3. Apply the manifests to the cluster:

    • Use kubectl apply -f deployment.yaml and kubectl apply -f service.yaml.
  4. Check the status:

    • kubectl get pods — ensure pods are running.
    • kubectl get services — verify accessibility.
  5. Configure access (if needed):

    • Ingress for HTTP routing.
    • LoadBalancer or NodePort for external access.

Example of a simple Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: myrepo/myapp:latest
        ports:
        - containerPort: 80

And a Service for access:

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

After this, the application will be running and accessible in the cluster.