Pod
-
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
-
Abstraction over a container

- Usually single Pod can runs 1 Application pod, it can also run multiple applications (not recommended),
- Pod is running environment or a layer on top of the container, (Kubernetes replace the container runtime or container technologies, so that there is no need to directly work with docker)
https://kubernetes.io/docs/concepts/workloads/pods/ (opens in a new tab)
Communication between Pods
- Each pod is assigned with an IP address, so that pods can communicate with each other using the internal IP address.
What happens when a pod dies ?
- Pods die very easily, a new IP address in assigned to the pod.

-
A pod dies, when the an application has crashed *(maybe the application node ran out of resources)
-
A new pod will be created at its place and when that happens the new pod is assigned with a new IP Address.
Service
Problem:
- When communication only happens based on IP Address, it need to be adjusted every time a pod dies, and a new IP Address is created.
- To avoid this problem, Service is used
Solution:
- Service is a static IP address, that is attached to each pod.
- Lifecycle of service and pod are not connected, i.e. even if the pod dies the IP address will not change.

Types of Service:
External
- An external service is used to make the application accessible to a browser.

- But database service, should not be open for public request.
Internal
- So, internal service is used, only for internal communication
Ingress

- before ingress:
http://<ip_address>:port - after ingress:
http://application.com
Config Map
Problem:
- Normally environment variables are usually in the built application
- i.e. To change any environment variable
- Re-built Container
- Push it to Repository
- Pull it to Pod
Solution:
- Config Map is an external configuration of your application, it contains configuration data like environment variables, services.

Secret
Problem:
- Storing username and password in config map is in-secure.
Solution:
- Secret is like a config map, but it is used to user credentials.
- it is base64 encoded

Volumes
Problem:
- If the database container dies, then it losses all its data.
- !! Kubernetes doesn't manage data persistence !!
Solution
- Volumes attaches a physical storage(local / cloud) to pod.

Deployments
Problem:
- If the application node dies, then users will face downtime (site cannot be reached).

Solution:
- ReplicaSet is used to maintain a stable set of replica Pods running at any given time.
- To create ReplicaSets, blueprint: Deployment is used
- Blueprint is an abstraction of pods.
https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ (opens in a new tab)

- Creating a replica or clone of node would prevent this issue.
- All node should be connected to the service.
- Service assigns a permanent IP address, and also works as a load balancer (it catches the request and forwards it to the least busy node).
Stateful Set
Problem:
- If the database node dies, application will face downtime
- DEPLOYMENT cannot create replicas of database node.
- To create replicas of database node, all the nodes has to be synced and has to access the same shared data storage. To avoid inconsistency
Solution:
- StatefulSet is the workload API object used to manage stateful applications.

- Deploying StatefulSet is k8s cluster is not easy
Recommended: Keep the database outside of the k8s cluster