Evolution of application deployment over the past 20 years.
Configure your local and remote lab environments.
Covers the resource types that are included with Kubernetes.
•Pod
•Job
Example microservice application.
Kubernetes manifests to deploy the demo application.
Explore how custom resources can add functionality
Install additional software to enhance the deployment.
Implement CI/CD for your applications (with GitOps!)
Each pod is assigned an IP address to make it reachable via the network, but the pods are considered ephemeral and may be deleted at any time.
To provide a stable way to address a set of pods (e.g. from a Deployment
) we use a Service
. There are a variety of kinds of services that provide access to pods from within or outside of the cluster.
We will create and examine multiple Services
to understand their behavior.
First, we'll create a namespace for these examples and set it as the default.
# task 01-create-namespace
# - Create a namespace for these examples and set as default
kubectl apply -f Namespace.yaml
kubens 04--service
We need a set of pods to route traffic to. In this case we will use a deployment.
# task 02-apply-deployment
# - Apply the Deployment configuration
kubectl apply -f Deployment.yaml
ClusterIP
is the default type of Service.
It exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster.
💡 Note: The selector
for the Service
defines a set of labels (in this case baz: pod-label
) that are used to identify the set of pods to route traffic to. This same label must be applied ot the pod (in this case from the Deployment template spec).
# Service.nginx-clusterip.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-clusterip
labels:
foo: service-label
annotations:
bar: service-annotation
spec:
type: ClusterIP
selector:
baz: pod-label
ports:
- protocol: TCP
port: 80
targetPort: 80
# task 03-apply-clusterip-service
# - Apply the ClusterIP Service.
kubectl apply -f Service.nginx-clusterip.yaml
A NodePort
type Service
exposes the Service
on each Node's IP at a static port (the NodePort).
A ClusterIP Service
, to which the NodePort Service
routes, is automatically created. You'll be able to contact the NodePort Service
from outside the cluster, using <NodeIP>:<NodePort>
.
🚨 Note: You will need to ensure your firewall rules allow inbound traffic on the corresponding port(s) for a NodePort to work!"
# Service.nginx-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-nodeport
spec:
type: NodePort
selector:
baz: pod-label
ports:
- protocol: TCP
port: 80
targetPort: 80
# nodePort: 30XXX (if unset, Kubernetes will assign a port within 30000-32767)
# task 04-apply-nodeport-service
# - Apply the NodePort Service
kubectl apply -f Service.nginx-nodeport.yaml
A LoadBalancer type Service
exposes the Service externally using a cloud provider's load balancer.
NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.
# Service.nginx-loadbalancer.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-loadbalancer
spec:
type: LoadBalancer
selector:
baz: pod-label
ports:
- protocol: TCP
port: 80
targetPort: 80
# task 05-apply-loadbalancer-service
# - Apply the LoadBalancer Service
kubectl apply -f Service.nginx-loadbalancer.yaml
Finally, clean up by deleting the namespace, which will also delete all resources within it.
# task 06-delete-namespace
# - Delete the namespace to clean up
kubectl delete -f Namespace.yaml