Table of contents
Kubernetes
It is a popular open-source container orchestration platform that helps manage and automate the deployment, scaling, and management of containerized applications. Kubernetes provides several networking components and services that enable communication between different components of a Kubernetes cluster.
Services:
Kubernetes services are used to expose a set of pods to other components of the cluster or to external clients. There are different types of services such as ClusterIP, NodePort, and LoadBalancer. ClusterIP services expose a set of pods internally within the cluster using a unique IP address. NodePort services expose a set of pods to the outside world by opening a specific port on each node in the cluster. LoadBalancer services expose a set of pods using a cloud provider's load balancer.
NodePort:
NodePort is a type of Kubernetes service that exposes a set of pods to the outside world by opening a specific port on each node in the cluster. NodePort services are typically used to expose applications running on a Kubernetes cluster to external clients, such as users accessing a web application.
When a NodePort service is created, Kubernetes assigns a unique port number in the range 30000-32767 on each node in the cluster. Incoming traffic to this port is then forwarded to the appropriate pod(s) behind the service based on the service's configuration. The pods are accessible from outside the cluster using any node's IP address and the assigned NodePort.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
type: NodePort
ports:
- name: http
port: 80
targetPort: 8080
nodePort: 30080
Load-Balancer:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: 8080
In this configuration, the service is named my-service
and selects pods labeled with app: my-app
. The service is configured as a LoadBalancer type, and exposes port 80 to the outside world. Incoming traffic to this port is then distributed by the cloud provider's load balancer to the pods behind the service's selector, which are listening on port 8080.
LoadBalancer services can be useful for production environments where scalability and high availability are critical. However, they require a cloud provider that supports load balancing, and may incur additional costs for the use of the load balancer. Additionally, for applications that require more advanced networking capabilities, such as SSL termination, path-based routing, and header-based routing, Kubernetes Ingress may be a more suitable solution.
Ingress:
Kubernetes Ingress is a powerful networking feature that provides a way to expose HTTP and HTTPS routes from outside the cluster to services within the cluster. Ingress controllers are responsible for implementing the Ingress specification by handling incoming requests and forwarding them to the appropriate services based on the rules defined in the Ingress resource.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
DNS:
Kubernetes DNS (Domain Name System) is a built-in service that provides name resolution for services within a cluster. Each service in a Kubernetes cluster is assigned a unique DNS name, which can be used by other services or pods to connect to the service.
CNI:
Kubernetes Container Network Interface (CNI) is a plugin-based networking architecture that enables Kubernetes to provide networking capabilities to containers. CNI plugins are responsible for configuring the network interfaces for pods and handling the routing of network traffic between pods and services. Popular CNI plugins include Calico, Flannel, and Weave Net.
In summary, Kubernetes provides several networking components and services such as Services, Ingress, DNS, and CNI that enable communication between different components of a Kubernetes cluster and provide advanced networking capabilities such as load balancing, service discovery, and network security.