Showing posts with label Z3_Kubernetes. Show all posts
Showing posts with label Z3_Kubernetes. Show all posts

Wednesday, November 20, 2019

Tuesday, November 19, 2019

HELM CHEAT SHEET

Cheatsheet: Kubernetes Helm

Choco install -y kubernetes-helm :
  •     helm version --short
  •     helm search: search for charts
  •     helm fetch: download a chart to our local directory to view
  •     helm install: upload the chart to Kubernetes
  •     helm list: list releases of charts
Helm Add Repositories :
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

Helm Search Repositories :

helm search repo bitnami/nginx
helm list
helm ls -all

Helm Install and Uninstall Package :
helm install bitnami/nginx mywebserver
helm install dashboard-demo stable/kubernetes-dashboard --set rbac.clusterAdminRole=true
helm uninstall mywebserver
helm delete mywebserver

Helm Rollback :
helm status mywebserver
helm history mywebserver
helm rollback mywebserver -1

Kubectl Help :

kubectl get svc,po,deploy
kubectl describe deployment mywebserver
kubectl get pods -l app.kubernetes.io/name=nginx
kubectl get service mywebserver-nginx -o wide
kubectl get pods -n kube-system


CLUSTERS FOR PRACTICE :

Setting Up Kubernetes (K8s) on Windows



DOWNLOAD & INSTALL :

1. Install Google Cloud SDK

2. Install kubectl
      gcloud components install kubectl


3. Install minikube
      Download, Rename and Copy to location
      C:\ & C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin
      minikube.exe 

4. Start Minikube
      minikube version
      minikube start
      minikube start --show-libmachine-logs --alsologtostderr
         minikube status
         minikube ssh
      minikube stop
      minikube delete

      minikube logs

     enable minikube addons:     
     minikube addons list
        minikube addons enable dashboard


5. kubectl Helper Commands:
      kubectl version -o json
      kubectl get namespace
      kubectl config use-context minikube
      kubectl cluster-info
      kubectl config view
      kubectl get nodes

      kubectl get all
      kubectl get all -n kube-system


6. Installing K8s Dashboard using kubectl

1. Deploy the Kubernetes dashboard to your single node cluster
kubectl apply -f  https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

2. Create a file => dashboard-admin-sa.yaml
# ------------------- Dashboard Service Account ------------------- #
apiVersion: v1
kind: ServiceAccount
metadata:
  name: dashboard-admin-sa
  namespace: kube-system
---
# ------------------- Dashboard-Cluster-Role ------------------- #
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: dashboard-admin-sa
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: dashboard-admin-sa
  namespace: kube-system


6. Open Cmder

7. Apply the service account and cluster role binding to your cluster
    kubectl apply -f dashboard-admin-sa.yaml

8. Start the kubectl proxy
    kubectl proxy

9. Get Token
    kubectl get secrets -n kube-system
    kubectl describe secrets dashboard-admin-sa -n kube-system

10. Run Dashboard
    minikube addons open dashboard
    minikube dashboard --url
 curl http://127.0.0.1:8001/ 
 http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

11. Delete Dasboard
      kubectl get all -n kube-system
      kubectl delete deployment kubernetes-dashboard --namespace kube-system
      service, role, rolebinding, sa, secret


12. Choose Token
paste the output from the previous command into the Token field, and
choose SIGN IN




Intro to Kubernetes

What is Kubernetes? Introduction to Kubernetes
Kubernetes is an orchestration engine and open-source platform for managing containerized application workloads and services, that facilitates both declarative configuration and automation. Kubernetes is also commonly referred as K8s.

Advantages of Kubernetes
Kubernetes can speed up the development process by making easy, automated deployments, updates (rolling-update) and by managing our apps and services with almost zero downtime. It also provides self-healing. Kubernetes can detect and restart services when a process crashes inside the container.

Kubernetes Architecture


Kubernetes Components
Web UI (Dashboard) :
Dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster itself along with its attendant resources.

Kubectl :
Kubectl is a command line configuration tool (CLI) for Kubernetes used to interact with master node of kubernetes. Kubectl has a config file called kubeconfig, this file has the information about server and authentication information to access the API Server.

Kubernetes Master :
Kubernetes Master is a main node responsible for managing the entire kubernetes clusters.
It handles the orchestration of the worker nodes.

It has three main components that take care of communication, scheduling and controllers.
API Server - Kube API Server interacts with API, Its a frontend of the kubernetes control plane.
Scheduler - Scheduler watches the pods and assigns the pods to run on specific hosts.
Kube-Controller-Manager - Controller manager runs the controllers in background which runs different tasks in Kubernetes cluster.

Some of the controllers are,
Node controller - Its responsible for noticing and responding when nodes go down.
Replication controllers - It maintains the number of pods. It controls how many identical copies of a pod should be running somewhere on the cluster
Replicasets controllers ensure number of replication of pods running at all time.
Endpoint controllers joins services and pods together.
Services account and Token controllers handles access managements.
Deployment controller provides declarative updates for pods and replicasets.
Daemon sets controller ensure all nodes run a copy of specific pods.
Jobs controller is the supervisor process for pods carrying out batch jobs
Services allow the communication.
Sateful sets specialized pod which offers ordering and uniqueness

Etcd :
etcd is a simple distribute key value store. kubernetes uses etcd as its database to store all cluster data. some of the data stored in etcd is job scheduling information, pods, state information and etc.

Worker Nodes :
Worker nodes are the nodes where the application actually running in kubernetes cluster, it is also know as minion. These each worker nodes are controlled by the master node using kubelet process.

Container Platform must be running on each worker nodes and it works together with kubelet to run the containers, This is why we use Docker engine and takes care of managing images and containers. We can also use other container platforms like CoreOS, Rocket.

Requirements of Worker Nodes:
1. kubelet must be running
2. Docker container platform
3. kube-proxy must be running
4. supervisord

Kubelet :
Kubelet is the primary node agent runs on each nodes and reads the container manifests which ensures that containers are running and healthy.

Kube-proxy :
Kube-proxy is a process helps us to have network proxy and load balancer for the services in a single worker node. It performs network routing for tcp and udp packets, and performs connection folding. Worker nodes can be exposed to internet via kube-proxy.

Pods :
A group of one or more containers deployed to a single node.
Containers in a pod share an IP Address, hostname and other resources.
Containers within the same pod have access to shared volumes.
Pods abstract network and storage away from the underlying container. This lets you move containers around the cluster more easily.
With Horizontal Pod Auto scaling, Pods of a Deployment can be automatically started and halted based on CPU usage.
Each Pod has its unique IP Address within the cluster.
Any data saved inside the Pod will disappear without a persistent storage

Deployment:
A deployment is a blueprint for the Pods to be created.
Handles update of its respective Pods.
A deployment will create a Pod by it’s spec from the template.
Their target is to keep the Pods running and update them (with rolling-update) in a more controlled way.
Pod(s) resource usage can be specified in the deployment.
Deployment can scale up replicas of Pods.

Service
A service is responsible for making our Pods discoverable inside the network or exposing them to the internet. A Service identifies Pods by its LabelSelector.

Types of services available:
1. ClusterIP
The deployment is only visible inside the cluster
The deployment gets an internal ClusterIP assigned to it
Traffic is load balanced between the Pods of the deployment

2. Node Port
The deployment is visible inside the cluster
The deployment is bound to a port of the Master Node
Each Node will proxy that port to your Service
The service is available at http(s)://:/
Traffic is load balanced between the Pods of the deployment

3. Load Balancer
The deployment gets a Public IP address assigned
The service is available at http(s)://:/
Traffic is load balanced between the Pods of the deployment

Hope you have got an idea about basics and introduction of kubernetes. In the next post, we have shown you How to Install & Configure Kubernetes Cluster with Docker on Linux.

<80> Also refer other articles,
Learn Kubernetes Basics Beginners Guide
How to Install Kubernetes Cluster with Docker on Linux
Create Kubernetes Deployment, Services & Pods Using Kubectl
Create Kubernetes YAML for Deployment, Service & Pods