1. Create a named Kubernetes cluster
eksctl create cluster --name [cluster-name] --profile [profile-name]eksctl create cluster --name [cluster-name] --profile [profile-name]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/v1kind: Deploymentmetadata:name: simple-flask-deploymentlabels:app: simple-flaskspec:replicas: 3selector:matchLabels:app: simple-flaskstrategy:type: RollingUpdaterollingUpdate:maxUnavailable: 2maxSurge: 2template:metadata:labels:app: simple-flaskspec:containers:- name: simple-flaskimage: [docker-username]/[image-name]securityContext:privileged: falsereadOnlyRootFilesystem: falseallowPrivilegeEscalation: falseports:- containerPort: 8080apiVersion: 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: 8080apiVersion: 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 createdkubectl apply -f deployment.yml # It will show the message as : # deployment.apps/simple-flask-deployment createdkubectl 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 deploymentkubectl get deployments# Check the rollout statuskubectl rollout status deployment/simple-flask-deployment# Show the pods in the clusterkubectl get pods# Show the services in the clusterkubectl describe services# Display information about the clusterkubectl cluster-info# 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# 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 podskubectl get all -A# Show all eventskubectl get events -w# Show component statuskubectl get componentstatuses# List all namespaces, all pods kubectl get all -A # Show all events kubectl get events -w # Show component status kubectl get componentstatuses# 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 deploymentkubectl delete deployments/simple-flask-deployment# Tear down your clustereksctl delete cluster eksctl-demo --profile <profile-name># Delete your deployment kubectl delete deployments/simple-flask-deployment # Tear down your cluster eksctl delete cluster eksctl-demo --profile <profile-name># 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 & Docker -> Deploy a Flask Application – Manually (Simple Steps)
暂无评论内容