> For the complete documentation index, see [llms.txt](https://edward-stevinson.gitbook.io/tech-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edward-stevinson.gitbook.io/tech-notes/computer-science/kubernetes.md).

# Kubernetes

In Kubernetes there are different **Kubernetes hosts**. Kubernetes takes care of managing hosts in clusters. By doing this this they can run containers. These containers are in pods.

## Pods

Within **pods** there are containers.

Also in a pod there are references to the **storage**.

All pods are monitored and if anything goes wrong then new pods are scheduled.

A **service** is a pod that has been made visible to the external world.

## Architecture

There is a **master node** and **worker nodes**.

### Master node

* The **api server** receives commands from **kubectl**.
* **etcd** -
* **scheduler** -
* **controller manager** -

### Worker node

* The **container engine** makes it possible to run the containers.
* **Service proxy**
* **kubelets**

## Deployments

A deployment provides declarative updates for pods and replica sets by which I mean it is responsible for keeping a set of pods running.

## Replica Set

A *ReplicaSet*'s purpose is to maintain a stable set of replica pods running at any given time. For eaxmple, if there are too many pods then the *ReplicationController* will delete the extra, or vice versa.

The difference between a replication set and a replication controller comes with their use of selectors. Replication sets use set-based selectors whilst replication controllers use equity-based selectors.

They are abbreviated to **rc**.

## Services

A *Service* enables network access to a set of Pods in Kubernetes. Services select pods based on their labels. When a network request is made to the service, it selects all pods in the cluster matching the service's selectorA *Service* enables network access to a set of Pods in Kubernetes. Services select pods based on their labels. When a network request is made to the service, it selects all pods in the cluster matching the service's selector.

When listing services there is a type category. This can take the following values:

* *ClusterIP* which exposes the service on a cluster-internal IP. This is the default service type and makes th service only reachable from within the cluster.
* *NodePort* exposes the service on each Node's IP at a static port. This routes to the the ClusterIP. You can contact the NodePort service by requesting `<NodeIP>:<NodePort>`
* *LoaddBalancer* exposes the service externally using a cloud provider's load balancer. NodePort and ClusterIP services will be automatically created and routed to.

## Labels

Labels are key/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. Labels can be used to organize and to select subsets of objects. Labels can be attached to objects at creation time and subsequently added and modified at any time. Each object can have a set of key/value labels defined. Each Key must be unique for a given object.

## Selectors

The *label selecotr* is the core grouping primitive in Kubernetes, used to identify a set of objects.

*Equity based* selectors allow for filtering by keys and values and matching objects must satisfy all constraints.

*Set based* selectors.

## Ingress

## Other

Alternatives to Kubernetes include **Docker Swarm** and **Apache Mesos** and **Amazon ECS** and **RedHat OpenShift**.
