03-Kubernetes Basics
03-Kubernetes Basics
Kubernetes Architecture
Kubernetes Architecture
Core primitives
Kubernetes objects
Kubernetes contains a number of abstractions that represent the state of your
system: deployed containerized applications and workloads, their associated
network and disk resources, and other information about what your cluster is doing.
❖ Pod
❖ Volume
❖ Service
❖ Namespace
Pods
A Pod is the basic building block of Kubernetes–the smallest and simplest unit in the
Kubernetes object model that you create or deploy. A Pod represents a running process on
your cluster.
Tightly coupled
❖ The atom of replication & placement
Command Description
kubectl get deployment Get info on current deployments
kubectl get rs Get info about the replica sets
Get info about the labels attached to those
kubectl get pods --show-labels pods
kubectl rollout status deployment/helloworld-deployment Get deployment status
ReplicationController
- replicas: 3
- selector:
- app: my-app
- version: v1 Live-update an application
$ kubectl rolling-update \
my-app-v1 my-app-v2 \
--image=image:v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 3 - replicas: 0
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 3 - replicas: 1
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 2 - replicas: 1
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 2 - replicas: 2
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 1 - replicas: 2
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 1 - replicas: 3
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Service
Rolling Updates - app: my-app
ReplicationController ReplicationController
- replicas: 0 - replicas: 3
- selector: - selector:
- app: my-app - app: my-app
- version: v1 - version: v2
Demo Placeholder
A deployment
Services
Services
• Pods are very dynamic, they come and go on the kubernetes cluster
• When using a replication-controller, pods are terminated and created during scaling
operations
• When using Deployments, when updating the image version, pods are terminated and new
pods take the place of older pods
• That's why pods should never be accessed directly, but always through a Service
• A Service is logical bridge between the "mortal" pods and other services or end-
users
Services
• When using the "kubectl expose" command earlier, you created a new service for
your pod, so it could be accessed externally
• Create a service will create an endpoints for your pod(s)
• A ClusterIP: a virtual IP address only reachable from within the cluster. ( this is default )
• A Nodeport: a port that is the same on each node that is also reachable externally
• A LoadBalancer: a LoadBalancer created by the cloud provider that will route the external
traffic to every node on the NodePort ( ELB on AWS )
Services
• The option just shown only allow you to create virtual IPs or Ports
• There is also a possibilities to use DNS Name
• ExternalName can provide a DNS name for the service
• e.g for service discovery using DNS
• This only works when the DNS add-on is enabled
• Note: By default service can run only between port 30000 - 32767, but you could change this behavior
by adding the --service-node-port-range= argument to the kube-apiserver ( in the init scripts )
Demo Placeholder
A new service
NETWORKING
BUILT-IN SERVICE DISCOVERY INTERNAL
LOAD-BALANCING
BUILT-IN SERVICE DISCOVERY INTERNAL
LOAD-BALANCING
ROUTE EXPOSES SERVICES EXTERNALLY
ROUTING AND EXTERNAL LOAD-BALANCING
● Pluggable routing architecture
○ HAProxy Router
○ F5 Router
MULTI-TENANT NETWORK
NODE NODE
● Multicast support
● Egress network policies POD POD POD POD
K8S SDN - NETWORKPOLICY
Example Policies
● Allow all traffic inside the project
● Allow traffic from green to gray
● Allow traffic to purple on 8080
apiVersion: extensions/v1beta1
k i n d : NetworkPolicy
metadata:
name: allow-to-purple-on-8080
spec:
podSelector:
matchLabels:
c o l o r : purple
ingress:
- ports:
- p r o t o c o l : tcp
p o r t : 8080
K8S SDN - OVS PACKETFLOW
• In our previous examples, I already have been using labels to tag pods
Labels
• Labels are not unique & multiple labels can be added to one object
• Once labels are attached to an object, you can use filters to narrow down results
• This is called Label Selector
• Using Label Selector, you can use matching expressions to match labels
• For instance, a particular pod can only run on a node labeled with "environment"
equal "Dev".
• More complex matching: "environment" in "Dev" or "QA".
Node Labels
• You can also use labels to tag nodes
• Once nodes are tagged, you can use label selectors to let pods only run on
specified nodes
tier: FE tier: BE
tier: FE tier: BE
Selectors
tier: FE tier: BE
tier: FE tier: BE
app = my-app
Selectors
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
tier: FE tier: BE
• After creating the yml file, you can use kubectl create:
Using Secrets
• You can create a pod that expose the secret as environment variables:
Demo Placeholder
Secrets
Setting up Wordpress
Thank You