Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

deployment.apps/nginx-deployment created

Exposing Services

Services

A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them - sometimes called a micro-service.


Defining a Service

Code Block
kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376


If we want to define a service which connects to outside IP addresses (maybe for a database in production), we would not specify a selector for our service and we would define an endpoint.

Code Block
kind: Service
apiVersion: v1
metadata:
  name: customer-db
spec:
  ports:
  - protocol: TCP
    port: 154321
    targetPort: 54321

Since no selector is specified, kubernetes will not create an Endpoint so we will have to.

Code Block
kind: Endpoints
apiVersion: v1
metadata:
  name: customer-db
subsets:
  - addresses:
      - ip: 1.2.3.4
    ports:
      - port: 54321


Types of Services

ClusterIP

Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType.

NodePort

 Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting <NodeIP>:<NodePort>

Image Added

LoadBalancer

Exposes the service externally using a cloud provider’s load balancerNodePort and ClusterIP services, to which the external load balancer will route, are automatically created.

Image Added

Ingress

Ingress, added in Kubernetes v1.1, 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.

    internet
        |
   [ Ingress ]
   --|-----|--
   [ Services ]

Image Added


An ingress can be configured to give services externally-reachable URLs, load balance traffic, terminate SSL, and offer name based virtual hosting. An ingress controller is responsible for fulfilling the ingress, usually with a loadbalancer, though it may also configure your edge router or additional frontends to help handle the traffic.

...

...