Architecture
Master node
Four processes run on every master node
- API Server: it’s a cluster gateway and gatekeeper for authentication (validate requests)
- Scheduler: schedule new pod, where to put the pod
- Controller manager: detect cluster states, restart pods if the pods crash
- etcd: cluster brain, all cluster changes stored in key-value format
Worker nodes
The worker nodes do the actual work meaning we will deploy services in these nodes, each node can have multiple pods (containers).
Thress processes must be installed on the node
- kubelet: communicate with master node
- kube poxy: internal communications
- pod: smallest unit of k8s
Components
Pod
Pods are the smallest computing units in Kubernetes. It can be created by using workload resources such as Deployment or Job. It has the following features:
- Usually only 1 application per pod
- Each pod has a virtual IP address (for internal interaction)
- Does not save any data (stateless)
Example for the Deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Service
Service is an abstraction that defines a logical set of Pods and a policy by which to access them. It could be considered as an abstract way to expose an application running on a set of pods as a network service. The pods can not communicate by virtual IP because the IP changes every time when the pod restarts.
Example for the Service file
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 9376 # port exposed by the pod
Ingress
Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.
Example for the Ingress file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /yourpath
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80