Getting Hands-on with Kubernetes using Simple Python Application (Part I)

Starting off with Minikube

brew install minikube
$ minikube start
output of the minikube command
$ minikube ip
Minikube status and IP address command for verification
  • Pods — runs one or more closely related containers, It is the smallest deployable units
  • Services — sets up networking in a Kubernetes cluster.
  • Deployment — Maintains a set of identical pods, ensuring that they have the correct config and that the right number of them exist.

Basic Python Flask Application Setup

$ docker build -t pyapplication .
$ docker run -itd --name python-app -p 5000:5000 pyapplication

Application Deployment via YAML Configuration

apiVersion: apps/v1
kind: Deployment
name: pyapplication
app: flask
app: flask
replicas: 3
type: RollingUpdate
app: flask
- name: pyapplication
image: pyapplicationimage
imagePullPolicy: Never
- containerPort: 5000
name: flask-container
apiVersion: v1
kind: Service
name: pyapplication
app: flask
- port: 5000
protocol: TCP
name: flask
app: flask
type: LoadBalancer
$ kubectl apply -f app-deployment.yml
kubectl get pods command results
minikube service deployment URL

Kubectl CLI cheatsheet

$ kubectl get componentstatus <gets status of all the components of control plane>
$ kubectl create -f <name.yml> (create k8s object from / deployment from YAML)
$ kubectl get deployment <metadata-name> -o yaml (gives deployed full YAML)
$ Kubectl get pods — all-namespaces
$ kubectl get pods — all-namespaces -o wide <gives nodes for the respective pods>
$ kubectl get namespaces
$ kubectl label pods <podname> key=value (put labels on running pods)
$ kubectl get pods -L <key> (-L for getting pods with mentioned label key)
$ kubectl get pods — field-selector status.phase=Running (shows all running pods)
$ kubectl get pods — all-namespaces — show-labels -o wide
$ kubectl get services <service-name>
$ kubectl exec <pod-name> — <command> (Execute a command from a pod)
E.g: kubectl exec busybox — curl
$ kubectl cluster-info (address of master & services)
$ kubectl config view (configuration)
$ kubectl describe nodes (show all nodes detail)
$ kubectl describe pods (show all pods detail)
$ kubectl get services — all-namespaces (show all services)
$ kubectl api-resources -o wide (view all resources)
$ kubectl get endpoints kube-scheduler -n kube-system -o yaml (view the kube scheduler endpoint / check current leader through annotation)
$ kubectl scale deployment <namespace> — replicas=0 -n service
(To restart the deployment, do this and then again with replicas=1)
$ kubectl delete -n application deployments demo-app (-n for namespace, then deployment type and then name of deployment
$ kubectl top node
$ kubectl top pod -n <namespace>

Database Deployments, Rolling updates and much more




Python, DevOps, Cryptography, Infra-Structure Automation.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Steve Jobs: You Were Wrong About The Best Developers

Let’s Deploy our Online Code Executor in Google Cloud

Adding Custom Sound Effects to a Flutter Mobile App


First step for reading OpenStack Nova source code

Flutter App

Ceremonies: Not Just for Tech

Friday story: How OpenBOM helps to overcome traditional BOM challenges

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Syed Saad Ahmed

Syed Saad Ahmed

Python, DevOps, Cryptography, Infra-Structure Automation.

More from Medium

ElasticSearch Python

Shell Commands 05: Linux Server Resources

File Handling and Operations in Python

Deploy Containerized Flask app to Heroku