Skip to content

Instantly share code, notes, and snippets.

@notionquest
Last active November 21, 2019 11:18
Show Gist options
  • Save notionquest/6a9cdc73d0f03a4d76be96de16d31c36 to your computer and use it in GitHub Desktop.
Save notionquest/6a9cdc73d0f03a4d76be96de16d31c36 to your computer and use it in GitHub Desktop.
Kubernetes

Basic Kubernetes Commands:-

  • minikube start --wait=false

To start the Kubernetes minikube

  • kubectl cluster-info

To get the cluster information

  • kubectl get nodes

To get the running nodes

  • kubectl get services

To get the services

  • kubectl get deployment

To get the deployments

  • kubectl get pv

To get persistent volumes

  • kubectl get pvc

To get persistent volume claims

  • kubectl get ing

To get the status of the ingress rules. Ingress rules are used to manage the routing.

  • kubectl get all

To get all deployments or what are the things deployed?

  • kubectl describe node master01 | grep "Container Runtime Version:"

Where master01 is the node name

Used describe command to grep the container runtime.

  • kubectl get pods --all-namespaces

To get pods and namespaces

  • kubectl set image deployment/http http=docker.io/sample/docker-http-server:latest

To create Pod based on Docker image. All images should be prefixed with container image registry. In the above case, it is Docker.

  • kubectl apply -f dashboard.yaml

To deploy the dashboard yaml with command

  • kubectl get pods -n kube-system

To get the Pods from kube-system namespace

Core Concepts:-

  1. Pods
  2. Replication Controller
  3. Services
  4. NodePorts

Pod?

Pod is a collection of Containers that make up a particular application.

kubectl get pods

What is Replication Controller?

The replication controller defines how many instances should be running, the Docker Image to use, and a name to identify the service.

Controller defines how the service runs.

kubectl get rc

To get Replication Controller.

Slave Pods are available.

What is Service?

A Kubernetes service is a named load balancer that proxies traffic to one or more containers. The proxy works even if the containers are on different nodes.

Use LoadBalancer service to handle external communications

kubectl get services kubectl describe services <service name>

Slave service are available.

How the service discovers the other Pods?

DNS

What is NodePort?

NodePort allows you to set well-known ports that are shared across your entire cluster. Such as 80:80.

kubectl describe service frontend | grep NodePort

To find NodePort from service. This is the port used for the webapp communication.

  • NodePort exposes the service on each Node's IP via the defined static port

NFS server:-

NFS server can be used to create persistent volume which can be used for stateful services such as MySQL, HTTP service etc.

Helm :-

Helm is the best way to find, share, and use software built for Kubernetes.

http://www.helm.sh/

Helm is a single binary that manages deploying Charts to Kubernetes.

helm search redis Search redis in package manager

helm inspect stable/redis Get more info using Inspect command

helm install stable/redis To install redis

helm ls To view all packages

What is Chart?

A chart is a packaged unit of kubernetes software. It can be downloaded from https://github.com/kubernetes/helm/releases

Weaver Scope

Weave Scope lets you monitor and control your containerized microservices applications. By providing a visual map of your Docker Containers, you can see the dependencies and communication links between them.

Scope automatically detects processes, containers, hosts. No kernel modules, no agents, no special libraries, no coding.

kubectl get pods -n weave To check whether Weave is deployed in the pod

By default, once deployed it will only be accessible from inside the cluster.

You can expose outside the cluster using VPN.

Weaver Uses:-

  • Used to visualize the containers
  • Monitor the interactions between the containers

kubeadm

https://github.com/kubernetes/kubeadm

Kubeadm is a tool built to provide best-practice fast paths for creating Kubernetes clusters.

Authorization Mechanisms:-

1. RBAC - Role Based Access Control:-

https://kubernetes.io/blog/2017/04/rbac-support-in-kubernetes/

Role-based access control, is an authorization mechanism for managing permissions around Kubernetes resources.

2. ABAC - Attribute Based Access Control:-

ABAC, Attribute Based Access Control, is a powerful concept. However, as implemented in Kubernetes, ABAC is difficult to manage and understand. It requires ssh and root filesystem access on the master VM of the cluster to make authorization policy changes. For permission changes to take effect the cluster API server must be restarted.

Container Runtimes:-

https://kubernetes.io/docs/setup/production-environment/container-runtimes/

To run containers in Pods, Kubernetes uses a container runtime. Here are the installation instructions for various runtimes.

  1. Docker
  2. CRI-O
  3. Containerd
  4. frakti - Hypervisor based

CRI-O:-

Because CRI-O is built for Kubernetes it means there are no Pause containers. This is just one of the many advantages of having a container runtime designed for Kubernetes.

Container Types:-

  1. Hypervisor based container runtimes
  2. Linux-namespace-based container runtimes

Master Node:-

The master is responsible for running the control plane components, etcd and the API server. Clients will communicate to the API to schedule workloads and manage the state of the cluster.

What is etcd?

https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/

etcd is a consistent and highly-available key value store used as Kubernetes’ backing store for all cluster data.

etcd is a leader-based distributed system. Ensure that the leader periodically send heartbeats on time to all followers to keep the cluster stable.

CNI - Container Network Interface :-

https://kubernetes.io/docs/concepts/cluster-administration/addons/

The Container Network Interface (CNI) defines how the different nodes and their workloads should communicate.

QoS - Quality of Service :-

https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/

When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:

  1. Guaranteed
  2. Burstable
  3. BestEffort

Networking Capabilities

  1. Cluster IP - is the default approach when creating Kubernetes service
  2. Target Ports
  3. NodePort
  4. External IPs
  5. Load Balancer

Target Port:-

  • Port on which the application will be accessed from outside
  • Port which the application is configured to listen on

Service Availability

Service can be accessed via the NodePort, TargetPort, ClusterIP and ExternalIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment