3. Orchestrating the Cloud with Kubernetes
📒 link
Overview
Goal
Provision a complete Kubernetes cluster using Kubernetes Engine
Deploy and manage Docker containers using
kubectl
Break an application into microservices using Kubernetes’ Deployments and Services
Example Application -> github
kelseyhightower/monolith - Monolith includes auth and hello services.
kelseyhightower/auth - Auth microservice. Generates JWT tokens for authenticated users.
kelseyhightower/hello - Hello microservice. Greets authenticated users.
nginx - Frontend to the auth and hello services.
Kubernetes can run on many different environments, from laptops to high-availability multi-node clusters, from public clouds to on-premise deployments, from virtual machine to bare metal.
Setup and requirements
✔️ Set the zone
✔️ Start up a cluster
Task 1. Get the sample code
✔️ Clone the GitHub repository from the Cloud Shell command line
✔️ Change into the directory needed for this lab
✔️ List the files to see what you’re working with
Task 2. Quick Kubernetes Demo
✔️ Launch a single instace of the nginx container
✔️ View the running nginx container
✔️ Expose nginx container outside of Kubernetes
✔️ List our services
✔️ Add the External IP to this command to hit the Nginx container remotely
Task 3. Pods
What is Pods?
The smallest deployable units of computing that you can create and manage in Kubernetes.
Group of one or more containers with shared storage and network resources, and a specification for how to run the containers.
What is Volumnes?
Data disk that live as long as the pods live, and can be used by the containers in that pod.
What is Namespace ?
Provides a mechanism for isolating groups of resources within a single cluster.
Task 4. Creating pods
✔️ Pod configuration file
Pod is made up of one container (ths monolith).
You’re passing a few arguments to our container.
You’re opening up port 80 for http traffic.
✔️ Create the monolith
✔️ Examine your pods. (Use the kubectl get pods command to list all pods running in the default namespace)
✔️ Get more information about the monolith pod
Task 5. Interacting with pods
By default, pods allocated a private IP address and cannot be reached outside of the cluster. Map a local port to a port inside the monolith pod
◾️ 2nd terminal
✔️ Set up port-forwarding
◾️ 1nd terminal
✔️ Start talking to your pod
✔️ See what heppens when you hit a secure endpoint
✔️ Logging in to get an auth token back from the monolith
✔️ Create an environment variable for the token (Since Cloud Shell does not handle copying long strings well, create an environment variable for the token.)
✔️ Use the token to hit secure endpoint
✔️ View the logs for the monolith Pod
◾️ 3rd terminal
✔️ View the logs for the monolith Pod
Get a stream of the logs happening in real-time
✔️ In the 1st teminal to interact with the monolith, you can see the logs updating(in the 3rd terminal):
✔️ Run an interactive shell inside the Monolith Pod. (This can come in handy when you want to troubleshoot from within a container)
✔️ Once you have a shell into the monolith container you can test external connectivity
Log out when done you’re done with interactive shell
Kubectl make it easy to interacting with pods. If you need to hit a container remotely.
Task 6. Services
What is Services?
An abstract way to expose an application running on a set of Pods as a network service.
Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.
Cluster IP (internal)
The default type means that this Service is only visible inside of the cluster
NodePort
NodePort gives each node in the cluster an externally accessible IP and
LoadBalancer
Adds a load balancer from the cloud provider which forwards traffic from the service to Nodes within it.
Ref
Task 7. Creating a service
Create a secure pod that can handle https traffic.
✔️ If you’ve changed directories, make sure you return to the ~/orchestrate-with-kubernetes/kubernetes
directory
✔️ Explore the monolith service configuration file
✔️ Creat the secure-monolith pods and their configuration data
✔️ Expose the secure-monolith Pod externally.
To do that, create a Kubernetes service.
✔️ Create the monolith service rom the monolith service configuration file
✔️ Allow traffic to the monolith service on the exposed nodeport
✔️ Get an external IP address for one of the nodes
✔️ Hitting the secure-monolith services using curl
Uh oh! that timed out.
Task 8. Adding labels to pods
✔️ See that you have quite a few pods running with the monolith label.
✔️ But what about “app=monolith” and “secure-enabled”?
✔️ Add the missing secure=enavled label to the secure-monolith Pod.
Now that pods are correctly labeled.
✔️ View the list of endpoints on the monolith service
✔️ Test this out by hitting one of our nodes again
Task 9. Deploying applications with Kubernetes
What is Deployments ?
Declarative way to ensure that the number of Pods running is equal to the desired number of Pods, specified by the user.
What is Replica Sets ?
Maintain stable set of replica Pods running at any given time.
It often used to guarantee the avaliability of a specified number of identical Pods.
Task 10. Creating a deployments
Monolith App with three separate pieces
auth : Generates JWT tokens for authenticated users.
hello : Greet authenticated users.
frontend : Routes trafic to the auth and hello services
✔️ Deployment configuration file
✔️ Create deployment object
✔️ Create a service for your auth deployment
✔️ Create and Expose deployment
hello deployment
frontend deployment
✔️ Interact with the frontend by grabbing its External IP and then curling to it
Summary
Provision a complete Kubernetes cluster using Kubernetes Engine
Deploy and manage Docker containers using
kubectl
Break an application into microservices using Kubernetes’ Deployments and a Services
Last updated