Working with Namespaces and Services in Kubernetes

Working with Namespaces and Services in Kubernetes

What are Namespaces and Services in k8s

  • A Namespace in Kubernetes is a way to partition cluster resources. It allows you to create a virtual cluster within a physical cluster.
  • Namespaces provide a scope for names. Names of resources, such as pods, services, and replication controllers, must be unique within a namespace, but not necessarily across namespaces.
  • Namespaces are useful for dividing cluster resources among multiple users, teams, or projects. They help avoid naming conflicts and provide isolation.

  • Read about Services, Load Balancing, and Networking in Kubernetes. Refer official documentation of kubernetes

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:

  • A Kubernetes namespace is a virtual cluster inside a physical cluster.
  • It provides a way to divide cluster resources between multiple users, teams, or projects.
  • Namespaces are a way to create isolated scopes within a cluster, preventing naming conflicts between resources.

Key Points:

  1. Isolation: Namespaces provide a level of isolation between different applications or environments running within the same Kubernetes cluster.
  2. Resource Quotas: You can set resource quotas on namespaces to limit the amount of CPU, memory, and other resources that can be used.
  3. Default Namespace: By default, Kubernetes has a namespace called "default," and resources without an explicitly specified namespace are created in this default namespace.

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:

  • In Kubernetes, a service is an abstraction that defines a logical set of pods and a policy by which to access them.
  • Services provide a stable endpoint (IP address and port) to interact with a set of pods, even if the underlying pods are dynamically scaled or replaced.

Key Points:

  1. Stable Network Endpoint: Services have a stable IP address and port, known as the cluster IP, that can be used by other services to communicate with the pods behind the service.
  2. Load Balancing: A service can distribute incoming network traffic across multiple pods. This load balancing ensures even distribution of requests and enhances the availability and reliability of the application.
  3. Service Types:ClusterIP: Exposes the service on a cluster-internal IP. This is the default service type.NodePort: Exposes the service on each Node's IP at a static port.LoadBalancer: Creates an external load balancer with a public IP, directing traffic to the service.ExternalName: Maps the service to the contents of the externalName field (e.g., a DNS name).

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        

要查看或添加评论,请登录

Daniel Gurus的更多文章

  • Why prefer Kubernetes ?

    Why prefer Kubernetes ?

    Kubernetes has become a cornerstone in modern container orchestration and management for a variety of reasons. Its…

    3 条评论
  • AWS EC2 Automation

    AWS EC2 Automation

    Instance Types General Purpose Instances (e.g.

  • AWS and IAM Basics

    AWS and IAM Basics

    AWS Identity and Access Management (IAM) is a web service provided by Amazon Web Services (AWS) that enables you to…

    2 条评论
  • Managing Persistent Volumes in Your Deployment

    Managing Persistent Volumes in Your Deployment

    What are Persistent Volumes in k8s In Kubernetes (k8s), a Persistent Volume (PV) is a cluster-wide piece of storage in…

  • Mastering ConfigMaps and Secrets in Kubernetes

    Mastering ConfigMaps and Secrets in Kubernetes

    What are ConfigMaps and Secrets in k8s ConfigMaps: ConfigMaps are Kubernetes resources that allow you to decouple…

  • Mastering Docker Best Practices: A DevOps Engineer's Guide

    Mastering Docker Best Practices: A DevOps Engineer's Guide

    Introduction: In the ever-evolving landscape of software development and deployment, Docker has emerged as a…

  • Devops Best Practices for Seamless Integration

    Devops Best Practices for Seamless Integration

    Introduction: In today's fast-paced tech world, the need for efficient collaboration between development and operations…

    1 条评论
  • Working with Services in Kubernetes

    Working with Services in Kubernetes

    What are Services in K8s In Kubernetes (K8s), a service is an abstraction that defines a logical set of pods and a…

  • Basic networking concepts for Devops engineer

    Basic networking concepts for Devops engineer

    Here are some fundamental networking concepts that are important for a DevOps engineer: IP Addressing: IPv4 and IPv6:…

    3 条评论
  • Launching your Kubernetes Cluster with Deployment

    Launching your Kubernetes Cluster with Deployment

    What is Deployment in k8s? A Kubernetes Deployment is an API resource that provides a declarative way to define the…

社区洞察

其他会员也浏览了