Versions Compared

Key

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

Table of Contents

Overview

Kubernetes, k8s, or kube, is an open source platform that automates container operations. It eliminates most of the existing manual processes, which involve the deploying, scaling, and managing of containerized applications.

Components

Kubernetes Master

...

  • ReplicaSet ensures that a specified number of Pod replicas are running at any given time.
  • Deployment is used to change the current state to the desired state.
  • StatefulSet is used to ensure control over the deployment ordering and access to volumes, etc.
  • DaemonSet is used to run a copy of a Pod on all the nodes of a cluster or on specified nodes.
  • Job is used to perform some task and exit after successfully completing their work or after a given period of time.


Describing an Object

When you create an object in Kubernetes, you must provide the object spec that describes its desired state, as well as some basic information about the object (such as a name). When you use the Kubernetes API to create the object (either directly or via kubectl), that API request must include that information as JSON in the request body. Most often, you provide the information to kubectl in a .yaml file. kubectl converts the information to JSON when making the API request.


Here’s an example .yaml file that shows the required fields and object spec for a Kubernetes Deployment:

Code Block
languageyml
titleapplication/deployment.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80


One way to create a Deployment using a .yaml file like the one above is to use the kubectl create command in the kubectl command-line interface, passing the .yaml file as an argument. Here’s an example:

$ kubectl create -f https://k8s.io/examples/application/deployment.yaml --record

The output is similar to this:

deployment.apps/nginx-deployment created

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.

   

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.

An ingress does not expose arbitrary ports or protocols. Exposing services other than HTTP and HTTPS to the internet typically uses a service of type Service.Type=NodePort or Service.Type=LoadBalancer.


Ingress providers:

https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-controllers


References