36
Kubernetes & Docker -> Deploy a Flask Application - Manually (Simple Steps)
eksctl create cluster --name [cluster-name] --profile [profile-name]
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.
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.
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
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
# 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
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
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>
36