Knowledge Transfer

Ethickfox kb page with all notes


Project maintained by ethickfox Hosted on GitHub Pages — Theme by mattgraham

==Kubernetes== (also known as k8s or “kube”) is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.

Upsides

130.png

Main parts

==Cluster== - is a grouping of nodes that run containerized apps in an efficient, automated, distributed, and scalable manner. A Kubernetes cluster consists of a set of worker machines, called nodes, that run containerized applications. Every cluster has at least one worker node.

==Control plane== - the collection of processes that control Kubernetes nodes. This is where all task assignments originate.

[!warn] Example ReplciationController - checks if there are requred number of replicas DeploymentController - Rolling updates and rollbacks of deployments

==Nodes== - these machines perform the requested tasks assigned by the control plane.

==Deployments== 

==ConfigMap== - configuration storage for application. Not suitable for passwords etc ==Secret== - stores data like ConfigMap, but securely. Could contain passwords

apiVersion: v1
kind: Namespace
metadata:
  name: development

15.png

==Kubelet== - this service runs on nodes, reads the container manifests, and ensures the defined containers are started and running.

==Replication controller==  - this controls how many identical copies of a pod should be running somewhere on the cluster.

==Service== - this decouples work definitions from the pods. Kubernetes service proxies automatically get service requests to the right pod—no matter where it moves in the cluster or even if it’s been replaced.

==kubectl== - the command line configuration tool for Kubernetes.

kubectl create deployment my-app --image=nginx
kubectl get nodes  # List available nodes
kubectl get deployments  # Check deployments
kubectl get pods  # Check running pods
kubectl expose deployment my-app --type=NodePort --port=80
kubectl scale deployment my-app --replicas=3
kubectl delete deployment my-app
kubectl delete service my-app

Kubernetes Explanation in Pictures

Node

it’s a virtual or physical machine

Usually 1 Application per Pod

Each Pod gets its own IP address

Pods are ephemeral

One node cluster - minikube

kubectl get node

apiVersion: v1
kind: ConfigMap 
metadata:
    name: mongo-config 
data:
    mongo-url: mongo-service


apiVersion: v1
kind: Secret
metadata:
    name: mongo-secret
type: 0paque
data:
    mongo_user: YWRtaW4=
    mongo_password: MwsfsZDFUMmUZN2Rm

apiversion:v1
kind: Deployment
metadata:
    name: mongo-deployment
    labels:
        app: mongo
spec:
    replicas: 1 
    selector:
        matchLabels:
            app: mongo
    template:
        metadata:
            labels:
                app: mongo
        spec:
            containers:
                - name: mongodb 
                image: mongo:5.0
                ports:
                      - containerPort: 27017
			   env:
					 - name: MONGO_INITDB_ROOT_USERNAME
					   valueFrom:
    secretKeyRef: 
name: mongo-secret
key: mongo-user
					 - name: MONGO_INITDB_ROOT_PASSWORD
					   valueFrom:
    secretKeyRef: 
name: mongo-secret
key: mongo-password
apiVersion: v1
kind: Service
metadata:
    name: mongo-service
spec:
    selector:
        app: mongo
ports:
    - protocol: TCP
    port: 8080
    targetPort: 27017



apiversion:v1
kind: Deployment
metadata:
    name: webapp-deployment
    labels:
        app: webapp
spec:
    replicas: 1 
    selector:
        matchLabels:
            app: webapp
    template:
        metadata:
            labels:
                app: webapp
        spec:
            containers:
                - name: webapp 
                image: nanajanashia/k8s-demo-app: v1.0
                ports:
                      - containerPort: 3000
			   env:
					 - name: USER_NAME
					   valueFrom:
    secretKeyRef: 
name: mongo-secret
key: mongo-user
					 - name: USER_PASSWORD
					   valueFrom:
    secretKeyRef: 
name: mongo-secret
key: mongo-password
					 - name: DB_URL
					   valueFrom:
    							configMapKeyRef: 
name: mongo-config
key: mongo-url
apiVersion: v1
kind: Service
metadata:
    name: webapp-service
spec:
	type:NodePort
    selector:
        app: webapp
ports:
    - protocol: TCP
    port: 80
    targetPort: 3000
	nodePort: 30100
kubectl apply -f mongo-config.yaml
kubectl get all
kubectl get configmap
kubectl get secret
kubectl logs webapp-deployment-deffd6bcc-gsmlt
kubectl get node -o wide
minikube ip

Commands Examples

kubectl cluster-info

kubectl get nodes
kubectl get namespaces
kubectl get pods -A      # in all namespaces
kubectl get pods -n development # in namespace development
kubectl get services -A
kubectl get deployments -n development

kubectl apply -f kub.yml

kubectl delete -f kub.yml
kubectl delete pod pod-info-development-78bbb77995-4mdf8 -n development

kubectl logs pod-info-development-78bbb77995-l47xp -n development

Managing Kubernetes for development

minikube start
kubectl get nodes  # Verify cluster is running

Spring_Boot_with_Kubernetes