M4 - Introduction To Kubernetes Workloads v1.7
M4 - Introduction To Kubernetes Workloads v1.7
Introduction to
Kubernetes Workloads
Welcome to the final module in Getting Started with GKE. So far on this course we
have learnt about Kubernetes and containerised applications, how to create a cluster
and populate it with nodes, how to manage your clusters, and how to move existing
non containerised applications into Kubernetes.
But Kubernetes is a large topic, that we don't have time to cover fully in this course. In
this final lesson, we will look at some of the Next Steps you might want to take in your
journey with Kubernetes.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
kube- kube-
cloud- controller-
manager manager Data storage services Networking services
Kubectl transforms your command-line entries into API calls that it sends to the Kube
API server within your selected Kubernetes cluster. Before it can do any work for you,
kubectl must be configured with the location and credentials of a Kubernetes cluster.
Proprietary + Confidential
API response
through
HTTPS
For example, take an administrator who wants to see a list of Pods in a cluster. After
connecting kubectl to the cluster with proper credentials, the administrator can issue
the kubectl ‘get pods’ command.
Kubectl converts this into an API call, which it sends to the Kube API server through
HTTPS on the cluster’s control plane server.
The Kube API server then returns the results to kubectl through HTTPS.
Finally, kubectl interprets the API response and displays the results to the
administrator at the command prompt.
Proprietary + Confidential
Before you can use kubectl to configure your cluster, you must configure it first.
Kubectl stores its configuration in a file in your home directory in a hidden folder
named .kube.
The configuration file contains the list of clusters and the credentials that you’ll use to
attach to each of those clusters. You may be wondering where you get these
credentials. For GKE, the service provides them to you through the gcloud command.
I’ll show you how that works in a moment.
To view the configuration, you can either open the config file or use the kubectl
command: ‘config view’. Just to be clear here: kubectl config view tells you about the
configuration of the kubectl command itself. Other kubectl commands tell you about
the configurations of your cluster and workloads.
Proprietary + Confidential
To connect to a GKE cluster with kubectl, retrieve your credentials for the specified
cluster first. To do this, use the ‘get-credentials’ gcloud command in any other
environment where you’ve installed the gcloud command-line tool and kubectl. Both
of these tools are installed by default in the Cloud Shell.
Can you figure out why the command is “gcloud get-credentials” rather than “kubectl
get-credentials”? It’s because the kubectl command requires credentials to work at all.
The gcloud command is how authorized users interact with Google Cloud from the
command line. The gcloud get-credentials command gives you the credentials you
need to connect with a GKE cluster if you are authorized to do so.
In general, kubectl is a tool for administering the internal state of an existing cluster.
But kubectl can’t create new clusters or change the shape of existing clusters; for that
you need the GKE control plane, which the gcloud command and the Cloud Console
are your interfaces to.
Proprietary + Confidential
... ...
Once the config file in the .kube folder has been configured, the kubectl command
automatically references this file and connects to the default cluster without prompting
you for credentials. Now let’s talk about how to use the kubectl command. Its syntax is
composed of several parts: the command, the type, the name, and optional flags.
‘Command’ specifies the action that you want to perform, such as get, describe, logs,
or exec. Some commands show you information, while others allow you to change the
cluster’s configuration.
‘TYPE’ defines the Kubernetes object that the ‘command’ acts upon. For example,
you could specify Pods, Deployments, nodes, or other objects, including the cluster
itself.
TYPE used in combination with ‘command’ tells kubectl what you want to do and the
type of object you want to perform that action on.
Proprietary + Confidential
‘NAME’ specifies the object defined in ‘TYPE.’ The Name field isn’t always needed,
especially when you’re using commands that list or show you information.
For example, if you run the command “kubectl get pods” without specifying a name,
the command returns the list of all Pods. To filter this list you specify a Pod’s name,
such as “kubectl get pod my-test-app ”. kubectl then returns information only on the
Pod named ‘my-test-app’.
Some commands support additional optional flags that you can include at the end of
the command.
Think of this as making a special request, like formatting the output in a certain way.
You could view the state of a Pod by using the command “kubectl get pod
my-test-app -o=yaml”. By the way, telling kubectl to give you output in YAML format is
a really useful tool. You’ll often want to capture the existing state of a Kubernetes
object in a YAML file so that, for example, you can recreate it in a different cluster.
You can also use flags to display more information than you normally see. For
instance, you can run the command “kubectl get pods -o=wide” to display the list of
Pods in “wide” format, which means you see additional columns of data for each of
the Pods in the list. One noteworthy piece of extra information you get in wide format:
which Node each Pod is running on.
Proprietary + Confidential
You can do many things with the kubectl command, from creating Kubernetes objects,
to viewing them, deleting them, and viewing or exporting configuration files.
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Deployments describe a desired state of Pods. For example, a desired state could be
that you want to make sure that 5 nginx pods are running at all times. Its declarative
stance means that Kubernetes will continuously make sure the configuration is
running across your cluster.
Proprietary + Confidential
Roll out updates to Roll back Pods to Scale or autoscale Well-suited for
the Pods previous revision Pods stateless applications
Every time you update the specification of the pods, for example, updating them to
use a newer container image, a new ReplicaSet is created that matches the altered
version of the Deployment. This is how deployments roll out updated Pods in a
controlled manner: old Pods from the old ReplicaSet are replaced with newer Pods in
a new ReplicaSet.
If the updated Pods are not stable, the administrator can roll back the Pod to a
previous Deployment revision.
You can scale Pods manually by modifying the Deployment configuration. You can
also configure the Deployment to manage the workload automatically.
.yaml file
Deployment object
Deployment controller
Node
Pod Pod Pod
In the spec.template section, a Pod template defines the metadata and specification
of each of the Pods in this ReplicaSet.
In the Pod specification, an image is pulled from Google Container Registry, and port
8080 is exposed to send and accept traffic for the container.
Proprietary + Confidential
The Deployment’s Progressing state indicates that a task is being performed. What
tasks? Creating a new ReplicaSet... or scaling up or scaling down a ReplicaSet.
The Deployment’s Complete state indicates that all new replicas have been updated
to the latest version and are available, and no old replicas are running.
Finally, the Failed state occurs when the creation of a new ReplicaSet could not be
completed. Why might that happen? Maybe Kubernetes couldn’t pull images for the
new Pods. Or maybe there wasn’t enough of some resource quota to complete the
operation. Or maybe the user who launched the operation lacks permissions.
When you apply many small fixes across many rollouts, that translates to a large
number of revisions, and to management complexity. You have to remember which
small fix was applied with which rollout, which can make it challenging to figure out
which revision to roll back to when issues arise. Remember, earlier we recommended
that you keep your YAML files in a source code repository? That will help you manage
some of this complexity.
Proprietary + Confidential
You can create a Deployment in three different ways. First, you create the
Deployment declaratively using a manifest file, such as the YAML file you’ve just
seen, and a kubectl apply command.
Your third option is to use the GKE Workloads menu in the Cloud Console. Here, you
can specify the container image and version, or even select it directly from Container
Registry. You can specify environment variables and initialization commands. You can
also add an application name and namespace along with labels. You can use the
View YAML button on the last page of the Deployment wizard to view the Deployment
specification in YAML format.
Proprietary + Confidential
The ReplicaSet created by the Deployment ensures that the desired number of Pods
are running and always available at any given time. If a Pod fails or is evicted, the
ReplicaSet automatically launches a new Pod. You can use the kubectl ‘get’ and
‘describe’ commands to inspect the state and details of the Deployment.
As shown here, you can get the desired, current, up-to-date, and available status of
all the replicas within a Deployment, along with their ages, using the kubectl ‘get
deployment’ command.
You can also output the Deployment configuration in a YAML format. Maybe you
originally created a Deployment with kubectl run, and then you decide you’d like to
make it a permanent, managed part of your infrastructure. Edit that YAML file to
remove the unique details of the Deployment you created it from, and then you can
add it to your repository of YAML files for future Deployments.
Proprietary + Confidential
For more detailed information about the Deployment, use the kubectl ‘describe’
command. You’ll learn more about this command in the lab.
Proprietary + Confidential
Another way to inspect a Deployment is to use the Cloud Console. Here you can see
detailed information about the Deployment, revision history, the Pods, events, and
also view the live configuration in YAML format.
Proprietary + Confidential
You now understand that a Deployment will maintain the desired number of replicas
for an application. However, at some point you’ll probably need to scale the
Deployment. Maybe you need more web front end instances, for example. You can
scale the Deployment manually using a kubectl command, or in the Cloud Console by
defining the total number of replicas. Also, manually changing the manifest will scale
the Deployment.
Proprietary + Confidential
You can also autoscale the Deployment by specifying the minimum and maximum
number of desired Pods along with a CPU utilization threshold. Again, you can
perform autoscaling by using the kubectl autoscale command, or from the Cloud
Console directly. This leads to the creation of a Kubernetes object called
HorizontalPodAutoscaler. This object performs the actual scaling to match the target
CPU utilization. Keep in mind that we’re not scaling the cluster as a whole, just a
particular Deployment within that cluster. Later in this module you’ll learn how to scale
clusters.
Proprietary + Confidential
When you make a change to a Deployment’s Pod specification, such as changing the
image version, an automatic update rollout happens. Again, note that these automatic
updates are only applicable to the changes in Pod specifications.
You can update a Deployment in different ways. One way is to use the kubectl ‘apply’
command with an updated Deployment specification YAML file. This method allows
you to update other specifications of a Deployment, such as the number of replicas,
outside the Pod template.
You can also use a kubectl ‘set’ command. This allows you to change the Pod
template specifications for the Deployment, such as the image, resources, and
selector values.
Another way is to use a kubectl ‘edit’ command. This opens the specification file using
the vim editor that allows you to make changes directly. Once you exit and save the
file, kubectl automatically applies the updated file.
Proprietary + Confidential
The last option for you to update a Deployment is through the Cloud Console. You
can edit the Deployment manifest from the Cloud Console and perform a rolling
update along with its additional options. Rolling updates are discussed next.
Proprietary + Confidential
When a Deployment is updated, it launches a new ReplicaSet and creates a new set
of Pods in a controlled fashion.
Its advantage is that updates are slowly released, which ensures the availability of the
application. However, this process can take time, and there’s no control over how the
traffic is directed to the old and new Pods.
Proprietary + Confidential
Service
We haven’t yet discussed how to locate and connect to the applications running in
these Pods, especially as new Pods are created or updated by your Deployments.
While you can connect to individual Pods directly, Pods themselves are transient. A
Kubernetes Service is a static IP address that represents a Service, or a function, in
your infrastructure. It’s a stable network abstraction for a set of Pods that deliver that
Service and, and it hides the ephemeral nature of the individual Pods.
Proprietary + Confidential
A blue/green deployment strategy is useful when you want to deploy a new version of
an application and also ensure that application services remain available while the
Deployment is updated.
When the Pods in the new Deployment are ready, the traffic can be switched from the
old blue version to the new green version. But how can you do this?
This is where a Kubernetes Service is used. Services allow you to manage the
network traffic flows to a selection of Pods. This set of Pods is selected using a label
selector.
Proprietary + Confidential
Here, in the Service definition, Pods are selected based on the label selector, where
Pods in this example belong to my-app and to version v1.
When a new Deployment, labelled v2 in this case, is created and is ready, the version
label in the Service is changed to the newer version, labeled v2 in this example. Now,
the traffic will be directed to the newer set of Pods, the green deployment with the v2
version label, instead of to the old blue deployment Pods that have the v1 version
label. The blue Deployment with the older version can then be deleted.
The advantage of this update strategy is that the rollouts can be instantaneous, and
the newer versions can be tested internally before releasing them to the entire user
base, for example by using a separate service definition for test user access.
The disadvantage is that resource usage is doubled during the Deployment process.
Proprietary + Confidential
Service
100%
The canary method is another update strategy based on the blue/green method, but
traffic is gradually shifted to the new version. The main advantages of using canary
deployments are that you can minimize excess resource usage during the update,
and because the rollout is gradual, issues can be identified before they affect all
instances of the application.
Service
66% 33%
Deployment (my-app-v1) Deployment (my-app-v2)
ReplicaSet ReplicaSet
Pod Pod Pod Pod Pod Pod
When the canary deployment starts, a subset of the traffic, 33% in this case, or a
single pod, is redirected to the new version, my-app-v2, while 66%, or two pods, from
the older version, my-app-v1, remain running.
Proprietary + Confidential
Service
100%
When the stability of the new version is confirmed, 100% of the traffic can be routed to
this new version. How is this done?
Proprietary + Confidential
In the blue/green update strategy covered previously, both the app and version labels
were selected by the Service, so traffic would only be sent to the Pods that are
running the version defined in the Service.
In a Canary update strategy, the Service selector is based only on the application
label and does not specify the version. The selector in this example covers all Pods
with the app:my-app label. This means that with this Canary update strategy version
of the Service, traffic is sent to all Pods, regardless of the version label.
This setting allows the Service to select and direct the traffic to the Pods from both
Deployments. Initially, the new version of the Deployment will start with zero replicas
running. Over time, as the new version is scaled up, the old version of the
Deployment can be scaled down and eventually deleted.
With the canary update strategy, a subset of users will be directed to the new version.
This allows you to monitor for errors and performance issues as these users use the
new version, and you can roll back quickly, minimizing the impact on your overall user
base, if any issues arise.
However, the complete rollout of a Deployment using the canary strategy can be a
slow process and may require tools such as Istio to accurately shift the traffic. There
are other deployment strategies, such as A/B testing and shadow testing. These
strategies are outside the scope of this course.
Proprietary + Confidential
Service
Deployment (my-app-v2)
ReplicaSet
Pod Pod Pod
A Service configuration does not normally ensure that all requests from a single client
will always connect to the same Pod. Each request is treated separately and can
connect to any Pod deployment. This potential can cause issues if there are
significant changes in functionality between Pods as may happen with a canary
deployment. To prevent this you can set the sessionAffinity field to ClientIP in the
specification of the service if you need a client's first request to determine which Pod
will be used for all subsequent connections.
Proprietary + Confidential
User traffic
Load balancer
Version 1 Version 2
With A/B testing, you test a hypothesis by using variant implementations. A/B testing
is used to make business decisions (not only predictions) based on the results
derived from data.
When you perform an A/B test, you route a subset of users to new functionality based
on routing rules as shown in the example here. Routing rules often include factors
such as browser version, user agent, geolocation, and operating system. After you
measure and compare the versions, you update the production environment with the
version that yielded better results.
User traffic
Load balancer
Version 1 Version 2
With shadow testing, you deploy and run a new version alongside the current version,
but in such a way that the new version is hidden from the users, as the diagram
shown illustrates. An incoming request is mirrored and replayed in a test environment.
This process can happen either in real time or asynchronously after a copy of the
previously captured production traffic is replayed against the newly deployed service.
You need to ensure that the shadow tests do not trigger side effects that can alter the
existing production environment or the user state.
Shadow testing has many key benefits. Because traffic is duplicated, any bugs in
services that are processing shadow data have no impact on production. When used
with tools such as Diffy, traffic shadowing lets you measure the behavior of your
service against live production traffic. This ability lets you test for errors, exceptions,
performance, and result parity between application versions. Finally, there is a
reduced deployment risk. Traffic shadowing is typically combined with other
approaches like canary testing. After testing a new feature by using traffic shadowing,
you then test the user experience by gradually releasing the feature to an increasing
number of users over time. No full rollout occurs until the application meets stability
and performance requirements.
Proprietary + Confidential
Blue/green
Need to maintain blue and green
Version 2 is released alongside version 1; the traffic is ✓ ✘ ✘ Instant
environments simultaneously
switched to Version 2 after it is tested.
Canary
Version 2 is released to a subset of users, followed by a ✓ ✓ ✘ Fast No extra setup required
full rollout.
A/B
Version 2 is released, under specific conditions, to a ✓ ✓ ✓ Fast No extra setup required
subset of users.
You can deploy and release your application in several ways. Each approach has
advantages and disadvantages. The best choice comes down to the needs and
constraints of your business. You should consider the following when choosing the
right approach.
What are your most critical considerations? For example, is downtime acceptable?
Do costs constrain you? Does your team have the right skills to undertake complex
rollout and rollback setups? Do you have tight testing controls in place, or do you
want to test the new releases against production traffic to ensure the stability of the
release and limit any negative impact? Do you want to test features among a pool of
users to cross-verify certain business hypotheses? Can you control whether targeted
users accept the update? For example, updates on mobile devices require explicit
user action and might require extra permissions.
Are microservices in your environment fully autonomous? Or, do you have a hybrid of
microservice-style applications working alongside traditional, difficult-to-change
applications? For more information, refer to deployment patterns on hybrid and
multi-cloud environments. Does the new release involve any schema changes? If yes,
are the schema changes too complex to decouple from the code changes?
The table shown here summarizes the salient characteristics of the deployment and
testing patterns. When you weigh the advantages and disadvantages of various
deployment and testing approaches, consider your business needs and technological
resources, and then select the option that benefits you the most.
Proprietary + Confidential
Clean up Policy:
● Default: 10 Revision
● Change: .spec.revisionHistoryLimit
So that’s ‘rollout.’ Next we’ll discuss how to roll back updates, especially in rolling
update and recreate strategies.
You roll back using a kubectl ‘rollout undo’ command. A simple ‘rollout undo’
command will revert the Deployment to its previous revision.
If you’re not sure of the changes, you can inspect the rollout history using the kubectl
‘rollout history’ command.
The Cloud Console doesn’t have a direct rollback feature; however, you can start
Cloud Shell from your Console and use these commands. The Cloud Console also
shows you the revision list with summaries and creation dates.
By default, the details of 10 previous ReplicaSets are retained, so that you can roll
back to them. You can change this default by specifying a revision history limit under
the Deployment specification.
Proprietary + Confidential
When you edit a deployment, your action normally triggers an automatic rollout. But if
you have an environment where small fixes are released frequently, you’ll have a
large number of rollouts. In a situation like that, you’ll find it more difficult to link issues
with specific rollouts. To help, you can temporarily pause this rollout by using the
kubectl rollout pause command. The initial state of the Deployment prior to pausing it
will continue its function, but new updates to the Deployment will not have any effect
while the rollout is paused. The changes will only be implemented once the rollout is
resumed.
When you resume the rollout, all these new changes will be rolled out with a single
revision.
You can also monitor the rollout status by using the kubectl ‘rollout status’ command.
Proprietary + Confidential
Delete a Deployment
$ kubectl delete deployment [DEPLOYMENT_NAME]
What if you’re done with a Deployment? You can delete it easily by using the kubectl
‘delete’ command, and you can also delete it from the Cloud Console. Either way,
Kubernetes will delete all resources managed by the Deployment, especially running
Pods.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Proprietary + Confidential
Lab Intro
Creating Google Kubernetes
Engine Deployments
The first task that you’ll learn to perform is to create a deployment manifest for a Pod
inside the cluster. You’ll then use both the Cloud Console and Cloud Shell to manually
scale Pods up and down. The next task will be to trigger a deployment rollout and a
deployment rollback. Various types of service types (ClusterIP, NodePort,
LoadBalancer) can be used with deployments to manage connectivity and availability
during updates. You’ll perform a task where you define service types in the manifest
and verify LoadBalancer creation. In your final task, you’ll create a new canary
deployment for the release of your application.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Pod eth0
10.4.0.2
Shared networking namespace
(localhost 127.0.0.1)
nginx legacy-app
tcp:80 tcp:8000
Shared storage
Remember, a Pod is a group of containers with shared storage and networking. This
is based on the “IP-per-pod” model of Kubernetes. With this model, each Pod is
assigned a single IP address, and the containers within a Pod share the same
network namespace, including that IP address.
For example, you might have a legacy application that uses nginx as a reverse-proxy
for client access. The nginx container runs on TCP port 80, and the legacy application
runs on TCP port 8000. Because both containers share the same networking
namespace, the two containers appear as though they’re installed on the same
machine. The nginx container will contact the legacy application by establishing a
connection to “localhost” on TCP port 8000.
Proprietary + Confidential
Production Namespace
This works well for a single Pod, but your workload doesn’t run in a single Pod.
Your workload is composed of many different applications that need to talk to each
other.
Node VM NIC
veth0 veth1
Node networking namespace
eth0 eth0
Pod 1 10.4.0.2
Pod 2 10.4.0.3
Shared networking namespace Shared networking namespace
(localhost 127.0.0.1) (localhost 127.0.0.1)
Each Pod has a unique IP address, just like a host on the network.
On a node, the Pods are connected to each other through the node's root network
namespace, which ensures that Pods can find and reach each other on that VM.
Using the node’s VM NIC, the root network namespace is able to forward traffic out of
the node.
This means that the IP addresses on the Pods must be routable on the network that
the node is connected to.
Proprietary + Confidential
In GKE, the nodes will get the Pod IP addresses from address ranges assigned to
your Virtual Private Cloud, or VPC.
VPCs are logically isolated networks that provide connectivity for resources you
deploy within Google Cloud, such as Kubernetes Clusters, Compute Engine
instances, and App Engine Flex instances. A VPC can be composed of many different
IP subnets in regions all around the world.
When you deploy GKE, you can select a VPC along with a region or zone. By default,
a VPC has an IP subnet pre-allocated for each Google Cloud region in the world. The
IP addresses in this subnet are then allocated to the compute instances that you
deploy in the region.
Proprietary + Confidential
VPC
GKE cluster nodes are compute instances that GKE customizes and manages for
you. These machines are assigned IP addresses from the VPC subnet that they
reside in.
Proprietary + Confidential
VPC
On Google Cloud, 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 4,000 IP addresses
for cluster-wide Services that you may create later. This mitigates the problem of
unexpectedly running out of service IP addresses.
Proprietary + Confidential
VPC
VPC-Native GKE clusters also create a separate Alias IP range for your Pods.
Remember, each Pod must have a unique address, so this address space will be
large. By default the address range uses a /14 block, which contains over 250,000 IP
addresses. That’s a lot of Pods.
Proprietary + Confidential
VPC
In reality, Google doesn’t expect you to run 250,000 Pods in a single cluster. Instead,
that massive IP address range allows GKE to divide the IP space among the nodes.
Using this large Pod IP range, GKE allocates a much smaller /24 block to each node,
which contains about 250 IP addresses. This allows for 1000 nodes, with over running
100 pods each, by default.
The number of nodes you expect to use and the maximum number of pods per node
are configurable, so you don't have to reserve a whole /14 for this.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Let’s look at storage and the idea of Volumes. In this class you’ll learn about the types
of storage abstractions that Kubernetes provides, such as Volumes and
PersistentVolumes. You’ll learn about how these differ, and how they can be used to
store and share information between Pods.
Proprietary + Confidential
Volumes PersistentVolumes
Remember that Kubernetes uses objects to represent the resources it manages. This
rule applies to storage as well as to Pods. All these objects function as useful
abstractions, which means that you can manage the resources they represent without
laborious attention to implementation details. Kubernetes provides storage
abstractions as Volumes and PersistentVolumes.
Kubernetes creates emptyDir volumes from the node’s local disk, or by using a
memory-backed file system.
● Secrets are similar to ConfigMaps. You should use Secrets to store sensitive
information, such as passwords, tokens, and ssh keys. Just like ConfigMap, a
Secret Volume is created to pass sensitive information to the Pods. These
Secret Volumes are backed by in-memory file systems, so the Secrets are
● never written to non-volatile storage. And it’s a common practice to obfuscate
the values that go into secrets using the familiar base64 encoding.
Beyond that, though, you should not assume that Secrets are secret just
because of the way they are configured. Having a differentiation between
ConfigMaps and Secrets allows you to manage non-sensitive and sensitive
Pod configuration data differently. You will probably apply different permissions
to each.
All these volume types are fundamentally similar. ConfigMap, Secret, and
downwardAPI are essentially EmptyDir Volumes pre-configured to contain
configurations from the GKE API. ConfigMap and Secret are discussed later in this
module, while downwardAPI is out of this course’s scope.
Proprietary + Confidential
Pod1 Pod2
An emptyDir volume is first created when a Pod is assigned to a node, and exists as
long as that Pod is running on that node. The emptyDir volume is initially empty. All
containers in the Pod can read and write the same files in the emptyDir volume,
though that volume can be mounted at the same or different paths in each container.
When a Pod is removed from a node for any reason, the data in the emptyDir is
deleted permanently.
It should be noted that a container crashing does not remove a Pod from a node. The
data in an emptyDir volume is safe across container crashes.
Proprietary + Confidential
Here, we’re creating a Pod with an emptyDir volume. Some uses for an emptyDir are
a scratch space, such as for a disk-based merge sort, checkpointing a long
computation for recovery from crashes or holding files that a content-manager
container fetches while a web server container serves the data.
Proprietary + Confidential
Abstracts storage
Promotes microservices
provisioning from storage
architecture.
consumption.
And application developers can easily claim and use provisioned storage using
PersistentVolumeClaims without creating and maintaining storage volumes directly.
Notice the separation of roles? It’s the job of administrators to make persistent
volumes available, and the job of developers to use those volumes in applications.
The two job roles can work independently of each other.
Let’s look at what is required for an application owner to consume Compute Engine
persistent disk storage, first using Pod-level Volumes and then using Cluster-level
PersistentVolumes and PersistentVolumeClaims in Pod manifests. You will see that
the second way is more manageable.
Pod
Storage
PVClaim
Classes
Pod
Persistent
Volumes PVClaim
In order to use PersistentVolumes the operations team that owns the specific cloud
implementation define the storage classes and manage the actual implementation
details of the Persistent Volumes.
This allows the operations team to manage the cloud services they wish to use and
allows the application owners to focus on what their application requires rather than
the specific implementation detail.
Proprietary + Confidential
Google Cloud’s Compute Engine service uses Persistent Disks for virtual machines’
disks, and Kubernetes Engine uses the same technology for PersistentVolumes.
Persistent Disks are network-based block storage that can provide durable storage.
First a 100-GB Compute Engine Persistent Disk is created using a gcloud command.
Before this Persistent Disk can be used by any Pod, someone or some process must
create it, and that person or process must have Compute Engine administration
rights.
Proprietary + Confidential
demo-container
API
etcd kubelet Pod
server
/demo-pod
demo-disk
When the Pod is created, Kubernetes uses the Compute Engine API to attach the
Persistent Disk to the node on which the Pod is running. The Volume is automatically
formatted and mounted to the container. If this Pod is moved to another node,
Kubernetes automatically detaches the Persistent Disk from the existing node and
re-attaches it to the newer node.
Proprietary + Confidential
Volumes:
pd-volume:
Type: vsphereVolume
PDName: demo-disk
FSType: ext4
Partition: 0
You can confirm that a Volume was mounted successfully using the kubectl describe
Pod command. Don’t forget that a Persistent Disk must be created before it can be
used. The Persistent Disk can have pre-populated data that can be shared by the
containers within a Pod. That’s very convenient. However, the application owner must
include the specific details of the Persistent Disk inside the Pod manifest for their
application and must confirm that the Persistent Disk already exists. That’s not very
convenient.
Hard coding Volume configuration information into Pod specifications in this way
means you may have difficulty porting data from one cloud to another. On GKE,
Volumes are usually configured to use Compute Engine Persistent Disks. In your
on-premises Kubernetes cluster, they might be VMware vSphere volume files, for
example, or even physical hard drives.
● Managed by Kubernetes.
Pod
● Manually or dynamically provisioned.
PVClaim
● Persistent Disks are used by GKE as
Persistent
PersistentVolumes. Volumes
Let’s take a closer look at how PersistentVolumes make the use of network storage
like this more manageable. The PersistentVolume abstraction has two components:
PersistentVolume (PV) and PersistentVolumeClaim (PVC).
Volume PersistentVolumeClaim
Pod Pod
Cluster PersistentVolume
What’s the critical difference between using Pod-level Volumes and Cluster-level
PersistentVolumes for storage? PersistentVolumes provide a level of abstraction that
lets you decouple storage administration from application configuration. The storage
in a PersistentVolume must be bound with a PersistentVolumeClaim in order to be
accessed by a Pod.
Proprietary + Confidential
Here’s how you create a PersistentVolume manifest for the same storage. Let’s take a
closer look at how this is used to make managing storage configuration for Pods
easier.
GKE has a default StorageClass named ‘standard’ to use the Compute Engine
Standard Persistent Disk type, as shown here on the right. In this example, the PV
definition on the left matches the GKE default StorageClass. In GKE clusters, a PVC
with no defined StorageClass will use this default StorageClass and provide storage
using a standard Persistent Disk.
Proprietary + Confidential
If you want to use an SSD Persistent Disk, you can create a new StorageClass, such
as this example named ssd. A PVC that uses this new StorageClass named ssd will
only use a PV that also has a StorageClass named ssd. In this instance, an SSD
Persistent Disk will be used.
Proprietary + Confidential
Add a PersistentVolumeClaim to the Pod, as shown here on the left. In our example,
the PersistentVolumeClaim named ‘pd-volume-claim’ has the ‘standard’
storageClassName, the ‘ReadWriteOnce’ accessMode, and a requested capacity of
100 gigabytes. When this Pod is started, GKE will look for a matching PV with the
same storageClassName and accessModes and sufficient capacity. The specific
cloud implementation doesn’t really matter, the specific storage used to deliver this
storage class is something the cluster administrators, not the application developers,
control.
What could go wrong with this? Well, what if application developers claim more
storage than has already been allocated to PersistentVolumes? PersistentVolumes
are managed by cluster administrators, but application developers make the
PersistentVolumeClaims, and this could lead to storage allocation failures.
Proprietary + Confidential
Once you create the new storage class with a kubectl apply command, you can view
it in the Cloud Console.
By the way, don’t confuse Kubernetes StorageClasses with Storage Classes that
Google Cloud Storage makes available. Although the features have the same name,
they are unrelated, because they come from different services and govern different
features. Google Cloud Storage is object storage for the web, while Kubernetes
StorageClasses are choices for how PersistentVolumes are backed.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Proprietary + Confidential
Lab Intro
Configuring Persistent Storage for
Google Kubernetes Engine
The tasks that you’ll perform include creating manifests for PVs and PVCs for
Compute Engine persistent disks, mounting Compute Engine persistent disk PVCs as
volumes in Pods, and using manifests to create StatefulSets. You’ll also mount
Compute Engine persistent disk PVCs as Volumes in StatefulSets and verify the
connection of pods in StatefulSets to particular PVs as the Pods are stopped and
restarted.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Proprietary + Confidential
Question #1
Question
Which control plane component does the kubectl command interact with?
A. etcd
B. kubelet
C. kube-apiserver
D. The GKE API
Proprietary + Confidential
Question #1
Answer
Which control plane component does the kubectl command interact with?
A. etcd
B. kubelet
C. kube-apiserver
D. The GKE API
A: Incorrect.
Feedback: Only kube-apiserver interacts with etcd.
B: Incorrect.
Feedback: Only kube-apiserver interacts with the kubelets on the node.
C: Correct.
D: Incorrect.
Feedback: kubectl is not aware of the GKE API.
Proprietary + Confidential
Question #2
Question
You want to use kubectl to configure your cluster, but first you must configure it. Where
does the kubectl command store its configuration file?
A. kubectl always prompts the user for credentials before executing commands.
B. kubectl uses the same authorization and credential tokens as the gcloud CLI
utilities.
C. The configuration information is stored in environment variables in the current shell
when required.
D. The configuration information is stored in the $HOME/.kube/config file.
Proprietary + Confidential
Question #2
Answer
You want to use kubectl to configure your cluster, but first you must configure it. Where
does the kubectl command store its configuration file?
A. kubectl always prompts the user for credentials before executing commands.
B. kubectl uses the same authorization and credential tokens as the gcloud CLI
utilities.
C. The configuration information is stored in environment variables in the current shell
when required.
D. The configuration information is stored in the $HOME/.kube/config file.
A: Incorrect.
Feedback: Review the lesson on the kubectl command.
B: Incorrect.
Feedback: Review the lesson on the kubectl command.
C: Incorrect.
Feedback: Review the lesson on the kubectl command.
D: Correct.
Proprietary + Confidential
Question #3
Question
You want to use a kubectl get command to identify which Node each Pod is running on.
Which command do you need to execute?
A. kubectl get nodes
B. kubectl get nodes -o=yaml
C. kubectl get pods
D. kubectl get pods -o=wide
Proprietary + Confidential
Question #3
Answer
You want to use a kubectl get command to identify which Node each Pod is running on.
Which command do you need to execute?
A. kubectl get nodes
B. kubectl get nodes -o=yaml
C. kubectl get pods
D. kubectl get pods -o=wide
A: Incorrect.
Feedback: Review the lesson on the kubectl command.
B: Incorrect.
Feedback: Review the lesson on the kubectl command.
C: Incorrect.
Feedback: Review the lesson on the kubectl command.
D: Correct.
Proprietary + Confidential
Question #4
Question
What is the purpose of a Service? Choose all that are true (2 correct answers)
A. To allow you to choose how Pods are exposed.
B. To allow you to put constraints on Pods' resource consumption.
C. To provide a load-balancing network endpoint for Pods.
D. To provide a way to inspect and diagnose code running in a Pod.
Proprietary + Confidential
Question #4
Answer
What is the purpose of a Service? Choose all that are true (2 correct answers)
A. To allow you to choose how Pods are exposed.
B. To allow you to put constraints on Pods' resource consumption.
C. To provide a load-balancing network endpoint for Pods.
D. To provide a way to inspect and diagnose code running in a Pod.
A: Correct.
B: Incorrect.
C: Correct.
D: Incorrect.
Proprietary + Confidential
Question #5
Question
After a Deployment has been created and its component Pods are running, which
component is responsible for ensuring that a replacement Pod is launched whenever a
Pod fails or is evicted?
A. DaemonSet
B. Deployment
C. ReplicaSet
D. StatefulSet
Proprietary + Confidential
Question #5
Answer
After a Deployment has been created and its component Pods are running, which
component is responsible for ensuring that a replacement Pod is launched whenever a
Pod fails or is evicted?
A. DaemonSet
B. Deployment
C. ReplicaSet
D. StatefulSet
A: Incorrect.
Feedback: Review the Deployments lesson.
B: Incorrect.
Feedback: Review the Deployments lesson.
C: Correct.
D: Incorrect.
Feedback: Review the Deployments lesson.
Proprietary + Confidential
Question #6
Question
Question #6
Answer
A: Correct.
B: Incorrect.
Feedback: Review the lesson on Deployments.
C: Incorrect.
Feedback: Review the lesson on Deployments.
D: Incorrect.
Feedback: Review the lesson on Deployments.
Proprietary + Confidential
Question #7
Question
Question #7
Answer
A: Incorrect.
Feedback: Review the lesson on Deployments.
B: Incorrect.
Feedback: Review the lesson on Deployments.
C: Correct.
D: Incorrect.
Feedback: Kubernetes does not care what languages the applications it controls are
written in.
Proprietary + Confidential
Question #8
Question
You have made a number of changes to your deployment and applied those changes.
Which command should you use to rollback the environment to the deployment identified
in the deployment history as revision 2?
A. Run ‘kubectl apply -f DEPLOYMENT_FILE --to-revision=2’
B. Run ‘kubectl rollout undo deployment’ twice.
C. Run ‘kubectl rollout undo deployment --to-revision=2’
D. Select the desired revision from the revision history list in the Cloud Console.
Proprietary + Confidential
Question #8
Answer
You have made a number of changes to your deployment and applied those changes.
Which command should you use to rollback the environment to the deployment identified
in the deployment history as revision 2?
A. Run ‘kubectl apply -f DEPLOYMENT_FILE --to-revision=2’
B. Run ‘kubectl rollout undo deployment’ twice.
C. Run ‘kubectl rollout undo deployment --to-revision=2’
D. Select the desired revision from the revision history list in the Cloud Console.
A: Incorrect.
Feedback: Review the lesson on Deployments.
B: Incorrect.
Feedback: Review the lesson on Deployments.
C: Correct.
D: Incorrect.
Feedback: Review the lesson on Deployments.
Proprietary + Confidential
Question #9
Question
You are resolving a range of issues with a Deployment and need to make a large number
of changes. Which command can you execute to group these changes into a single
rollout, thus avoiding pushing out a large number of rollouts?
A. kubectl delete deployment
B. kubectl rollout pause deployment
C. kubectl rollout resume deployment
D. kubectl stop deployment
Proprietary + Confidential
Question #9
Answer
You are resolving a range of issues with a Deployment and need to make a large number
of changes. Which command can you execute to group these changes into a single
rollout, thus avoiding pushing out a large number of rollouts?
A. kubectl delete deployment
B. kubectl rollout pause deployment
C. kubectl rollout resume deployment
D. kubectl stop deployment
A: Incorrect.
Feedback: Review the lesson on Deployments.
B: Correct.
C: Incorrect.
Feedback: Review the lesson on Deployments.
D: Incorrect.
Feedback: Review the lesson on Deployments.
Proprietary + Confidential
Question #10
Question
Question #10
Answer
A: Correct.
B: Incorrect.
Feedback: Review the lesson on Pod networking.
C: Incorrect.
Feedback: Review the lesson on Pod networking.
Proprietary + Confidential
Question #11
Question
Your Pod has been rescheduled and the IP address that was assigned to the Pod when it
was originally scheduled is no longer accessible. What is the reason for this?
A. The new Pod IP address is blocked by a firewall.
B. The new Pod has received a different IP address.
C. The old Pod IP address is blocked by a firewall.
D. The Pod IP range for the cluster is exhausted.
Proprietary + Confidential
Question #11
Answer
Your Pod has been rescheduled and the IP address that was assigned to the Pod when it
was originally scheduled is no longer accessible. What is the reason for this?
A. The new Pod IP address is blocked by a firewall.
B. The new Pod has received a different IP address.
C. The old Pod IP address is blocked by a firewall.
D. The Pod IP range for the cluster is exhausted.
A: Incorrect.
Feedback: Review the lesson on Pod networking.
B: Correct.
C: Incorrect.
Feedback: Review the lesson on Pod networking.
D: Incorrect.
Feedback: Review the lesson on Pod networking.
Proprietary + Confidential
Question #12
Question
Question #12
Answer
A: Incorrect.
Feedback: Review the lesson on volumes.
B: Incorrect.
Feedback: Review the lesson on volumes.
C: Incorrect.
Feedback: Review the lesson on volumes.
D: Correct.
Proprietary + Confidential
Question #13
Question
How can a Pod request persistent storage without specifying the details of how that
storage is to be implemented?
A. By using a gcePersistentDisk
B. By using a PersistentVolume
C. By using a PersistentVolumeClaim
D. By using an emptyDir
Proprietary + Confidential
Question #13
Answer
How can a Pod request persistent storage without specifying the details of how that
storage is to be implemented?
A. By using a gcePersistentDisk
B. By using a PersistentVolume
C. By using a PersistentVolumeClaim
D. By using an emptyDir
A: Incorrect.
Feedback: Review the video on PersistentVolumes and PersistentVolumeClaims.
B: Incorrect.
Feedback: Review the video on PersistentVolumes and PersistentVolumeClaims.
C: Correct.
D: Incorrect.
Feedback: Review the video on PersistentVolumes and PersistentVolumeClaims.
Proprietary + Confidential
Question #14
Question
Question #14
Answer
A: Correct.
B: Incorrect.
Feedback: Review the lesson on Kubernetes Volumes.
C: Incorrect.
Feedback: Review the lesson on Kubernetes Volumes.
D: Incorrect.
Feedback: Review the lesson on Kubernetes Volumes.
Proprietary + Confidential
Agenda
The kubectl command Lab: Configuring Persistent Storage
for Google Kubernetes Engine
Deployments
Quiz
Lab: Creating Google Kubernetes
Engine Deployments Summary
Pod Networking
Volumes
Proprietary + Confidential
Summary
Work with the kubectl command.
That concludes the introduction to Kubernetes Workloads. In this module you learned
how to understand and work with Kubernetes using the kubectl command. You
looked at how to create and use Deployments. You learned about Pod networking
and how to create Services to expose applications running within Pods, allowing them
to communicate with each other, and the outside world. Lastly you learnt about
storage abstractions which will allow you configure and select the appropriate storage
type for your applications.
Proprietary + Confidential