k8s

Kubernetes Concept 6

k8s sharing

Posted by frankie on July 15, 2019

Pod networking

A Pod is a group of containers with shared storage and networking

IP per pod model

Imgur

Because both containers share the same networking namespace, the two containers appears as through they are installed on the same machine. The nginx container will contact the legacy application by establishing a connection to local host on tcp port 8000.

Imgur

Imgur

Imgur

Imgur

Two pods communicate on the same node.

Imgur

Imgur

Pod IP is from the VPC (logically isolated networks that provide connectivity for resources you deploy within GCP. such as kubernetes clusters, Compute Engine instances, and App Engine)

A VPC can be composed of many different IP subnets in regions all around the world.

Imgur

Imgur

Imgur

The pod’s IP address are part of the address range called an alias IP. GKE automatically configures your VPC to recognize this range of IP address as an authorized secondary subnet of IP addresses.

As a result, the pod’s traffic is permitted to pass the anti-spoofing filters on the network.

Imgur

Also, because each node maintains a separate IP address base for its pods, the nodes don’t need to perform network address translation on the pod IP address. That means that the pods can directly connect to each other using their native IP addreses.

The traffic from your cluster is routed or peered inside GCP, but becomes now translated, at the node IP address if it has to exit GCP.

Imgur

On GCP, Alias IPs allow you to configure additional secondary IP addresses or IP ranges on your Compute Engine VM instances. VPC-Native GKE clusters automatically create an Alias IP range to reserve approximately 4000 IP addresses for cluster-wide Services that you may create later.

Services

In an ever-changing container environment, Services give Pods a stable IP address and name that remains the same through updates, upgrades, scalability changes, and even Pod failures. Instead of connecting to a specific Pod, applications on Kubernetes rely on Services to locate suitable Pods and forward the traffic via those Services rather than directly to Pods.

Imgur

Imgur

Imgur

Imgur

Finding Services (Service Discovery)

There are several ways to find a Service in GKE

  • Environment Variables
  • Kubernetes DNS
  • lstio

Imgur

Problems: For created pods, the environment variables does work, so no way to control them.

Imgur

IP based solution to connect the service and pods

Imgur

Imgur

Imgur

For pod and service in the same namespace, use the short DNS name, otherwise, the namespace is needed for DNS solution.

Imgur

Imgur

Imgur

Imgur

Imgur

Service Types and Load Balancers

* ClusterIP
* NodePort
* Load balancer

Imgur

Imgur

Internal communications within a cluster - ClusterIP

Imgur

NodePort is built on top of cluster IP’s service.

Imgur

Imgur

How load balancers work

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Ingress Resource

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Container-Native Load Balancing

Imgur

Imgur

Imgur

Network Security

Imgur

Imgur

Imgur

Imgur

Imgur