|
| 1 | +### Kubernetes |
| 2 | + |
| 3 | +Website kubernetes.io |
| 4 | +Type Cluster management software and container orchestration |
| 5 | +Repository https://github.com/kubernetes/kubernetes |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +-What is Kubernetes |
| 10 | + |
| 11 | +- Kubernetes (commonly stylized as K8s) |
| 12 | +- Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. |
| 13 | +- It groups containers that make up an application into logical units for easy management and discovery. |
| 14 | +- Platform for automating deployment, scaling, and operations of application containers across clusters of hosts |
| 15 | +- Originally developed by Google in 2014, now maintained by Cloud Native Computing Foundation(CNCF) |
| 16 | +- Implemented in Go. |
| 17 | +- Works with a range of container tools, including Docker. |
| 18 | +- help to shape the evolution of technologies that are container-packaged, dynamically-scheduled and microservices-oriented |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +# Architecture |
| 23 | + |
| 24 | +sites : |
| 25 | +1. https://thenewstack.io/kubernetes-an-overview/ |
| 26 | +2. https://x-team.com/blog/introduction-kubernetes-architecture/ |
| 27 | +3. https://medium.com/@abhaydiwan/kubernetes-introduction-and-twelve-key-features-cdfe8a1f2d21 |
| 28 | +4. https://medium.com/jorgeacetozi/kubernetes-master-components-etcd-api-server-controller-manager-and-scheduler-3a0179fc8186 |
| 29 | + |
| 30 | +- Kubernetes follows the master-slave architecture |
| 31 | + |
| 32 | +I] Kubernetes Master |
| 33 | + - Kubernetes Masters act as the control unit for a cluster. |
| 34 | + - Manages its workload and directs communication across the system. |
| 35 | + - A cluster needs 1 or more Masters to run |
| 36 | + |
| 37 | +- API Server |
| 38 | + - The API server provides endpoints for developers and operators to interact with the cluster |
| 39 | + - Key component and serves the Kubernetes API using JSON over HTTP, provides both the internal and external |
| 40 | + interface to Kubernetes. |
| 41 | + - Processes and validates REST requests and updates state of the API objects in etcd |
| 42 | + |
| 43 | +- Controller Manager |
| 44 | + - Controller Manager manages controllers that work to bring Kubernetes to the desired state. |
| 45 | + - This include scheduling controllers and Replication controllers. |
| 46 | + - Is the process in which the core Kubernetes controllers like DaemonSet Controller and Replication Controller run. |
| 47 | + - It communicate with the API server to create, update and delete the resources they manage (pods, service |
| 48 | + endpoints, etc.) |
| 49 | + |
| 50 | +- Scheduler |
| 51 | + - Scheduler is responsible for actually doing the resource management of pods based. |
| 52 | + - Process that actually assigns workloads to specifc nodes in the cluster is the scheduler. |
| 53 | + - It manages on which node an unscheduled pod should run on based on resource availability |
| 54 | + |
| 55 | +- etcd |
| 56 | + - To store confguration data that can be accessed by each of the nodes in cluster. |
| 57 | + - Stores cluster state and confguration in the form of key-value |
| 58 | + |
| 59 | +----------- |
| 60 | + |
| 61 | +# II] Kubernetes Nodes |
| 62 | + - The Node, also known as Worker or Minion |
| 63 | + - Kubernetes Nodes actually run the workloads(containers). |
| 64 | + - Kubernetes needs at least 1 node to run. |
| 65 | + - In small setups, the node and the master can be the same. |
| 66 | + |
| 67 | +- Kubelet |
| 68 | + - Kubelet is an agent that runs on each node that receives the instructions from the Master about what to do |
| 69 | + on the node. |
| 70 | + - Is responsible for the running state of each node. |
| 71 | + - Ensures all containers on the node are healthy. |
| 72 | + - Takes cares of Containers(POD) lifecycle management. |
| 73 | + |
| 74 | +- cAdvisor |
| 75 | + - cAdvisor collects telemetry about the pods running on the nodes such as network, CPU and RAM usage. |
| 76 | + - Is the agent that monitors and gathers resource usage and performance metrics of containers on each node. |
| 77 | + |
| 78 | +- Kube-Proxy |
| 79 | + - Is an implementation of a network proxy and a load balancer for the pods running on the node |
| 80 | + - It supports the service abstraction along with other networking operation. |
| 81 | + - It is responsible for routing trafc to the appropriate container based on IP and port number of the incoming request. |
| 82 | + - It uses linux ip tables in backend to perform its operation. |
| 83 | + |
| 84 | +- POD |
| 85 | + - POD is collection of one or more container(s). |
| 86 | + - smallest deplyable unit |
| 87 | + - Small group of tightly coupled containers |
| 88 | + - shared network and data volumes |
| 89 | + - routable IP address |
| 90 | + - The containers in the pod share resources such as storage, CPU and RAM |
| 91 | + - Network resources are connected to the pod |
| 92 | + - Containers is the lowest level of microservice which holds the running application, libs or their dependancies. |
| 93 | + |
| 94 | +- Plugin Network |
| 95 | + - Plugin Network uses a driver to create an overlay network between Kubernetes Nodes. |
| 96 | + - This allows pods to communicate seamlessly between nodes on a Kubernetes Cluster. |
| 97 | + - eg. Flannel (Flannel is a very simple overlay network that satisfies the Kubernetes requirements. Many people have reported success with Flannel and Kubernetes.) or weave-net or calico. |
| 98 | + |
| 99 | + |
| 100 | +# Services |
| 101 | + |
| 102 | +https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0 |
| 103 | + |
| 104 | +- services provide permanent virtual IP and DNS name |
| 105 | +- It is an exposure of pods, replica set, controllers etc. on a port through kube-proxy |
| 106 | +- Types of Services: |
| 107 | + - ClusterIP |
| 108 | + - NodePort |
| 109 | + - ExternalIP |
| 110 | + - ExternalName |
| 111 | + |
| 112 | +1. ClusterIP |
| 113 | + - A ClusterIP service is the default Kubernetes service. |
| 114 | + - Service gets virtual IP which only used to communicate within the cluster. |
| 115 | + - It gives you a service inside your cluster that other apps inside your cluster can access. There is no external access. |
| 116 | + |
| 117 | +2. NodePort |
| 118 | + - Derives properties of ClusterIP. |
| 119 | + - Makes a service accessible from outside the cluster |
| 120 | + - In addition, it gets port from range 30000-32767 mapped with all nodes in cluster |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +# Tools |
| 126 | + |
| 127 | +1. Kubeadm |
| 128 | + - A administration tool for setting up and managing kubernetes clusters. Kubeadm runs on the Kubernetes host. |
| 129 | + |
| 130 | +2. Kubectl |
| 131 | + - The command line interface for interacting with a Kubernetes clusters |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +# Kubernetes Features |
| 137 | + |
| 138 | +1. Automatic binpacking |
| 139 | +Automatically places containers based on their resource requirements and other constraints, while not sacrificing availability. Mix critical and best-effort workloads in order to drive up utilization and save even more resources. |
| 140 | + |
| 141 | +2. Horizontal scaling |
| 142 | +Scale your application up and down with a simple command, with a UI, or automatically based on CPU usage. |
| 143 | + |
| 144 | +3. Automated rollouts and rollbacks |
| 145 | +Kubernetes progressively rolls out changes to your application or its configuration, while monitoring application health to ensure it doesn't kill all your instances at the same time. If something goes wrong, Kubernetes will rollback the change for you. Take advantage of a growing ecosystem of deployment solutions. |
| 146 | + |
| 147 | +4. Storage orchestration |
| 148 | +Automatically mount the storage system of your choice, whether from local storage, a public cloud provider such as GCP or AWS, or a network storage system such as NFS, iSCSI, Gluster, Ceph, Cinder, or Flocker. |
| 149 | + |
| 150 | +5. Self-healing |
| 151 | +Restarts containers that fail, replaces and reschedules containers when nodes die, kills containers that don't respond to your user-defined health check, and doesn't advertise them to clients until they are ready to serve. |
| 152 | + |
| 153 | +6. Service discovery and load balancing |
| 154 | +No need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives containers their own IP addresses and a single DNS name for a set of containers, and can load-balance across them. |
| 155 | + |
| 156 | +7. Secret and configuration management |
| 157 | +Deploy and update secrets and application configuration without rebuilding your image and without exposing secrets in your stack configuration. |
| 158 | + |
| 159 | +8. Batch execution |
| 160 | +In addition to services, Kubernetes can manage your batch and CI workloads, replacing containers that fail, if desired. |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +# Creating a single master cluster with kubeadm |
| 166 | + |
| 167 | +Sites : |
| 168 | +1. https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/ |
| 169 | +2. https://kubernetes.io/docs/tasks/tools/install-kubeadm/ |
| 170 | + |
| 171 | +# Steps : |
| 172 | + |
| 173 | +- Installing kubeadm, kubelet and kubectl |
| 174 | + |
| 175 | +1. vim /etc/yum.repos.d/kubernetes.repo |
| 176 | + - Add this |
| 177 | + [kubernetes] |
| 178 | + name=Kubernetes |
| 179 | + baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 |
| 180 | + enabled=1 |
| 181 | + gpgcheck=1 |
| 182 | + repo_gpgcheck=1 |
| 183 | + gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg |
| 184 | + |
| 185 | +2. setenforce 0 |
| 186 | +3. yum install -y kubelet kubeadm kubectl |
| 187 | +4. systemctl enable kubelet && systemctl start kubelet |
| 188 | + |
| 189 | +5. vim /etc/sysctl.d/k8s.conf |
| 190 | + - Add this |
| 191 | + net.bridge.bridge-nf-call-ip6tables = 1 |
| 192 | + net.bridge.bridge-nf-call-iptables = 1 |
| 193 | + |
| 194 | +6. sysctl --system |
| 195 | + |
0 commit comments