Working with Namespaces and Services in Kubernetes
What are Namespaces and Services in k8s
Services : It is a method for exposing a network application that is running as one or more Pods in your cluster. It serves as an abstraction layer that defines a set of pods and the policies used to access them. It is used to provide a stable IP address and DNS name, and can load balance traffic between pods. This enables communication between pods and decouples the client from the backend pods.
Load Balancing : It is the process of distributing network traffic efficiently among multiple backend services. In K8s, load balancing is typically achieved by using a Service of type LoadBalancer, which creates an external load balancer in the cluster’s network and distributes traffic to the pods of the Service.
Networking : Kubernetes networking gives you flexibility and helps drive the adoption of loosely coupled service architectures.
Namespaces and Services in Kubernetes
Namespaces:
Definition:
领英推荐
Key Points:
kubectl Contexts: When working with multiple clusters, each cluster can have its own set of namespaces. The combination of cluster and namespace is often referred to as a kubectl context.
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace
Services:
Definition:
Key Points:
Selectors: Services use label selectors to determine which pods they should target. Pods with matching labels are part of the service.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080