DEV Community

Cover image for Kubernetes & Docker -> Deploy a Flask Application - Manually (Simple Steps)
Senichi
Senichi

Posted on

Kubernetes & Docker -> Deploy a Flask Application - Manually (Simple Steps)

1. Create a named Kubernetes cluster

eksctl create cluster --name [cluster-name]  --profile [profile-name]
Enter fullscreen mode Exit fullscreen mode

2. Image registry (get or create)

Create/Build a Docker Image and push it to their Docker Hub repository.

Docker images are loaded from the container registry into Kubernetes pods. Access to the pods are exposed to consumers through a service.

3. Deployment

The manual deployment needs a YAML file that will describe things like number of replicas, deployment strategy, Docker image name, and port on which the application can be accessed.

1. Deployment mockup yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-flask-deployment
  labels:
    app: simple-flask
spec:
  replicas: 3
  selector:
    matchLabels:
      app: simple-flask
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 2
      maxSurge: 2
  template:
    metadata:
      labels:
        app: simple-flask
    spec:
      containers:
      - name: simple-flask
        image: [docker-username]/[image-name]
        securityContext:
          privileged: false
          readOnlyRootFilesystem: false
          allowPrivilegeEscalation: false
        ports:
          - containerPort: 8080
Enter fullscreen mode Exit fullscreen mode

2. In your terminal

Navigate to deployment-mockup-yaml-file, and run:

kubectl apply -f deployment.yml

# It will show the message as :
# deployment.apps/simple-flask-deployment created
Enter fullscreen mode Exit fullscreen mode

3. Other useful commands are:

# Verify the deployment
kubectl get deployments

# Check the rollout status
kubectl rollout status deployment/simple-flask-deployment

# Show the pods in the cluster
kubectl get pods

# Show the services in the cluster
kubectl describe services

# Display information about the cluster
kubectl cluster-info
Enter fullscreen mode Exit fullscreen mode

4. Troubleshoot:

If your pods do not show up as "Ready" while running the kubectl get nodes1 command, use the following troubleshooting tips:

# List all namespaces, all pods
kubectl get all -A

# Show all events
kubectl get events -w

# Show component status
kubectl get componentstatuses
Enter fullscreen mode Exit fullscreen mode

5. Clean up

Let's delete the deployment as well the Kubernetes cluster:

# Delete your deployment
kubectl delete deployments/simple-flask-deployment

# Tear down your cluster
eksctl delete cluster eksctl-demo --profile <profile-name>
Enter fullscreen mode Exit fullscreen mode

Kubernetes Cheatsheet

Top comments (0)