Skip to main content

Services in K8s

  • In Kubernetes, a Service is a method for exposing a network application that is running as one or more Pods in your cluster.

  • The set of Pods targeted by a Service is usually determined by a selector that you define.

  • For example, consider a stateless image-processing backend which is running with 3 replicas. Those replicas are fungible—frontends do not care which backend they use. While the actual Pods that compose the backend set may change, the frontend clients should not need to be aware of that, nor should they need to keep track of the set of backends themselves. The Service abstraction enables this decoupling.
  • Here is an example of a service of type NodePort which exposes a port(Nodeport) of a Node in the kubernetes cluster and also describes which port on the pod would the calls be forwarded to (targetPort) - *A nodePort is a temporary solution to expose the applications to the internet, usually done for testing purposes, other types of services e.g. load-balancer etc. can provide a permanent solution
    • apiVersion: v1
      kind: Service
      metadata:
        name: eggplantsapi-service
      spec:
        selector:
          app: eggplants
        ports:
          - port: 80  # Expose on port 80 for simplicity, adjust as needed
            nodePort: 30100
            targetPort: 3000
            name: http
          - port: 81
            nodePort: 30101
            targetPort: 5000
            name: http-api
        type: NodePort
  • https://www.youtube.com/watch?v=RQbc_Yjb9ls
  • Difference between LoadBalancer service and other types of services is that LoadBalancer get an external public IP address
  • A Loadbalancer's IP address is stable
  • A Loadbalancer routes traffic to the nodes in your cluster.
  • When a LoadBalancer service is created then the underlying ClusterIP and NodePort services are also created.
  • Know more about loadbalancer service: https://www.youtube.com/watch?v=7o6koGCsoSc


  • Different Service Types




Comments

Popular posts from this blog

Networking in Kubernetes

Pods that are running inside Kubernetes are running on a private, isolated network. By default they are visible from other pods and services within the same Kubernetes cluster, but not outside that network Every Pod has a unique IP address And it is reachable from all other Pods in the K8s cluster A pod is a host, just like your laptop, having an ip-address and a range of ports that can be alloted to containers A container runs on a specific port inside a pod In a Kubernetes environment, when services are deployed within the same namespace , they can communicate with each other using the service name as the hostname e.g. in the following snippet from appsetting.json form a .net core project, ' document-api'  is the name of the service "DocumentApiConfiguration" : { "BaseUrl" : "http://document-api/" } What if I want to access a service from another namespace? When you want to access a service from another namespace in Kubernetes, you typica...

Terraform

It is an Infrastructure as Code tool Normally, if one has to configure VMs or other resources on the cloud, they have to go to the cloud provider's website and click a lot to get things done as supposed, terraform can do all of that provided you tell it precisely what to do in a .tf file e.g. which cloud provider you are using(GCP, Azure etc), which resource to configure with what specifications. One writes the file in hashicorp language (kinda like JSON) Free and Open source One has to install the CLI terraform init terraform apply  (to make the changes to cloud) terraform destroy

Kubernetes

Some keywords: Node A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster Clusters Kubernetes coordinates a highly available cluster of computers (nodes) that are connected to work as a single unit Namespace Namespaces are a way to organize clusters into virtual sub-clusters — they can be helpful when different teams or projects share a Kubernetes cluster . Any number of namespaces are supported within a cluster , each logically separated from others but with the ability to communicate with each other Kubernetes: Kubernetes is a portable, extesible open-source platform for managing and orchestration containerized workloads . It abstracts away complex container management tasks Provides us with declarative configuration to orchestrate containers in different computing environments This orchestration platform gives you the same ease of use and flexibility you might already know from Platform-as-a-Service (PaaS) or Infrastruct...