Flashcards
Aron Midgård - 8 Services
Cards in this deck (10)
- 1What are services?Services are the agents which connect Pods together, or provide access outside of the cluster, with the idea that any particular Pod could be terminated and rebuilt. Typically using Labels, the refreshed Pod is connected and the microservice continues to provide the expected resource via an Endpoint object.
- 2Service Update PatternThe default update pattern is for a rolling deployment, where new Pods are added, with different versions of an application, and due to automatic load balancing, receive traffic along with previous versions of the application.
- 3Accessing an Application with a ServiceThe basic step to access a new service is to use kubectl.
The kubectl expose command created a service for the nginx deployment. This service used port 80 and generated a random port on all the nodes. A particular port and targetPort can also be passed during object creation to avoid random values. The targetPort defaults to the port, but could be set to any value, including a string referring to a port on a backend Pod. Each Pod could have a different port, but traffic is still passed via the name. Switching traffic to a different port would maintain a client connection, while changing versions of software, for example.
The kubectl get svc command gave you a list of all the existing services, and we saw the nginx service, which was created with an internal cluster IP.
The range of cluster IPs and the range of ports used for the random NodePort are configurable in the API server startup options.
Services can also be used to point to a service in a different namespace, or even a resource outside the cluster, such as a legacy application not yet in Kubernetes. - 4Service Types - ClusterIPThe ClusterIP service type is the default, and only provides access internally (except if manually creating an external endpoint). The range of ClusterIP used is defined via an API server startup option.
- 5Service Types - NodePortThe NodePort type is great for debugging, or when a static IP address is necessary, such as opening a particular address through a firewall. The NodePort range is defined in the cluster configuration.
- 6Service Types - LoadBalancerThe LoadBalancer service was created to pass requests to a cloud provider like GKE or AWS. Private cloud solutions also may implement this service type if there is a cloud provider plugin, such as with CloudStack and OpenStack. Even without a cloud provider, the address is made available to public traffic, and packets are spread among the Pods in the deployment automatically.
- 7Service Types - ExternalNameA newer service is ExternalName, which is a bit different. It has no selectors, nor does it define ports or endpoints. It allows the return of an alias to an external service. The redirection happens at the DNS level, not via a proxy or forward. This object can be useful for services not yet brought into the Kubernetes cluster. A simple change of the type in the future would redirect traffic to the internal objects.
- 8Local Proxy for DevelopmentWhen developing an application or service, one quick way to check your service is to run a local proxy with kubectl. It will capture the shell, unless you place it in the background. When running, you can make calls to the Kubernetes API on localhost and also reach the ClusterIP services on their API URL. The IP and port where the proxy listens can be configured with command arguments.
Run a proxy:
$ kubectl proxy
Starting to serve on 127.0.0.1:8001
Next, to access a ghost service using the local proxy, we could use the following URL, for example, at http://localhost:8001/api/v1/namespaces/default/services/ghost.
If the service port has a name, the path will be http://localhost:8001/api/v1/namespaces/default/services/ghost:. - 9DNSDNS has been provided as CoreDNS by default as of v1.13. The use of CoreDNS allows for a great amount of flexibility. Once the container starts, it will run a Server for the zones it has been configured to serve. Then, each server can load one or more plugin chains to provide other functionality.
The 30 or so in-tree plugins provide most common functionality, with an easy process to write and enable other plugins as necessary.
Common plugins can provide metrics for consumption by Prometheus, error logging, health reporting, and TLS to configure certificates for TLS and gRPC servers. - 10Verifying DNS RegistrationTo make sure that your DNS setup works well and that services get registered, the easiest way to do it is to run a pod in the cluster and exec in it to do a DNS lookup.
Information
- Description
- Flashcards on Aron Midgård - 8 Services, created by Assar Pettersson on 12/05/2020.
- Created by
- Assar Pettersson · May 2020
- Updated
- May 12, 2020
- Views
- 0
- Rating