
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Test
Kubernetes clusters are configured using manifests, or configs, written in YAML or JSON. These configurations include important Kubernetes objects such as Namespaces, ClusterRoles, ClusterRoleBindings, Roles, RoleBindings, PodSecurityPolicy, NetworkPolicy, and ResourceQuotas, etc.
These declarative configs can be applied by hand or with automated tooling. The preferred method is to use an automated process to establish and maintain a consistently managed environment from the beginning.
Anthos Config Management is a solution to help manage these resources in a configuration-as-code like manner. Anthos Config Management utilizes a version-controlled Git repository (repo) for configuration storage along with configuration operators which apply configs to selected clusters.
Anthos Config Management allows you to easily manage the configuration of many clusters. At the heart of this process are the Git repositories that store the configurations to be applied on the clusters.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
After you complete the initial sign-in steps, the project dashboard appears.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
Set up the Cloud Shell environment for command-line access to your clusters:
Set kubectl
to use the context for the onprem cluster:
Create a JSON Web Token (JWTs) for the remote-admin-sa
secret that represents the Kubernetes Service Account that will be used for GKE Connect:
Output:
Select the token contents in the Cloud Shell (this will automatically copy the contents).
Ctrl+c
or
Command+c
to copy to the clipboard. Those keystrokes will
copy over new line breaks from the display,instead of treating the token
as a single line of text.
Simply selecting text in Cloud Shell will put the contents in your
clipboard buffer.
Go to Navigation > Kubernetes Engine > Clusters, scroll to the right, click on the 3 dots to open the dropdown menu of the the onprem-connect cluster row, and click on the Log in option.
When prompted, select Token as the authentication type, and paste the previously copied token, then click Login.
You should now see two clusters listed with green checkmarks which indicates both clusters are registered successfully.
Visit the Gateways, Services & Ingress page, select Services tab and find the frontend-external service address for each cluster.
The Config Management Operator is a Kubernetes controller that manages
Anthos Config Management in a Kubernetes cluster. In this task, you install
the Operator as a system workload on both clusters. You also install the
nomos
command-line tool which helps you to understand the state of Anthos
Config Management in your clusters.
Set the Zone environment variable
In Cloud Shell, switch your context to the gke cluster:
Download the configuration file for Config Management resources:
Review the file in the Cloud Shell editor to get a sense of what is being created on your cluster.
The file is acm-lab/config-management-operator.yaml
:
Exit the editor and apply the configuration to the gke cluster:
You may need to click Open Terminal in Cloud Shell.
Output
Use the GCP Console to verify that a system workload called config-management-operator has been created. Visit Navigation > Kubernetes Engine > Workloads.
Remove the filter to show system objects, and you should see the deployment.
Switch contexts, and apply the configuration file to the onprem cluster:
Using the console, or the kubectl
command, verify that the Config Management
Operator has been deployed to the onprem cluster.
In Cloud Shell, download the nomos
command-line tool:
Use nomos status
to check if Anthos Config Management is properly installed and configured:
Output:
In this case, config management is installed but not yet configured for your clusters.
When nomos status
reports an error, it also shows any additional error
text available to help diagnose the problem under
Config Management Errors
.
You will correct the issues you see here in later steps.
Anthos Config Management requires you to store your configurations in a Git repository. In this task, you set up that repository.
Anthos Config Management supports any Git repo including GitHub and Google Cloud Source Repositories. In this lab, you will use Cloud Source Repositories.
Set the username and email address for your Git activities:
Get sample config files for the lab:
Take a moment to review the structure of the config directory. Click the Open Editor button in Cloud Shell, then in the explorer section of the editor, drill down into acm-lab/training-data-analyst/courses/ahybrid/v1.0/AHYBRID071/config.
Take a minute to review the subdirectories and the contents of the config files you find.
Click Open Terminal to return to the Cloud Shell command line, and initialize the config directory as a new local Git repo:
Output:
Create a Cloud Source Repositories repo named anthos_config
to host your code:
Set gcloud.sh
to supply credentials for Git access:
Add your newly created config repository as a Git remote:
Push your code to the new repository's master branch:
Verify your repo and source code were created in Cloud Source Repositories. Select Navigation > VIEW ALL PRODUCTS > Source Repositories. Then select the anthos_config repository.
The Anthos Config Management Config Operator, when running on your clusters,
needs read-only access to your Git repo, so it can read the latest committed
configs, then check and/or apply them to your clusters. The credentials for
this read-only access to your Git repo are stored in the git-creds
secret
on each enrolled cluster.
When using Cloud Source Repositories, an SSH keypair is the recommended approach to authorize access to your repo.
Using Cloud Shell, generate an SSH keypair:
Save the private key to a secret on each cluster:
The SSH public key portion of your generated SSH keypair needs to be registered with Cloud Source Repositories. The Config Operators on your clusters can then use the SSH private key, just stored as a cluster secret, to access your config repository.
In the Cloud Source Repositories console, click the three dots in the top-right toolbar, then click Manage SSH Keys.
Click Register SSH Key.
You may be prompted to enter your Qwiklabs user password
.
Enter config demo key
in the Key Name field.
You can choose a different key name if needed.
From Cloud Shell, copy the key value from the output of this command:
ssh-
or ecdsa-
,
and ends with an email address.
Ctrl+c
or
Command+c
to copy to the clipboard. Those keystrokes will
copy over new line breaks from the display,instead of treating the key
value as it should.
Simply selecting text in Cloud Shell will put the contents in your
clipboard buffer.
Return to Cloud Source Repositories, and paste the copied key from your public key file into the Key field.
Click Register.
You will now see your registered key on the Manage SSH Keys page.
To configure the Config Management Operators to read from your repo, you will create configuration files for the ConfigManagement CustomResources and apply them to your clusters.
You have been provided configuration files for your two clusters. You will need to modify each to point to your hosted repo.
Using the Cloud Shell Code Editor, open the gke configuration file for editing:
Replace the [qwiklabs-user-email]
placeholder with the email address for your
Qwiklabs user, as shown in the upper left corner of the Qwiklabs window.
Replace the [qwiklabs-project]
placeholder with GCP Project ID for your
project shown in the upper left corner of the Qwiklabs window.
Notice also that a variety of options can be included to configure
how the resource interacts with your repo. For example, auth
is set to ssh indicating ConfigManagement should use the keys
stored previously.
For more details about the fields, check the installation instructions.
Save the changes to your file.
Repeat the process for the onprem configuration file:
You can copy the line from gke-config-management.yaml
.
Back in Cloud Shell, switch contexts to your gke cluster and list Namespaces:
Output:
Describe the prod Namespace and note the labels you see:
Output:
List the ClusterRoles and the ClusterRoleBindings on the gke cluster:
Output:
and
Output:
List the RoleBindings for the prod service.
Output:
In the Cloud Shell editor, navigate to acm-lab/training-data-analyst/courses/ahybrid/v1.0/AHYBRID071/config. Note the folder structure:
In the cluster folder, open and review the configuration files you find. One defines a ClusterRole you wish to add to each cluster, and the second defines a ClusterRoleBinding you wish to add to each cluster.
In the namespaces folder, open the dev folder and then the namespace.yaml file inside. This file defines a Namespace you wish to have created on every cluster.
In the namespaces folder, open the prod folder and then the namespace.yaml file inside. This file defines a Namespace you wish to have created on every cluster. Note the env label.
In the namespaces folder, open the selector-sre-support.yaml file. Note that the NamespaceSelector will select only Namespaces that have a given label. In this case, the label is env:prod - so only the prod Namespace will be affected by configurations that use this selector.
In the namespaces folder, open the rolebinding-sre.yaml file. Note the annotations which indicate that this config should be applied using a selector.
In Cloud Shell, apply the configuration to the gke cluster.
Output:
Apply the configuration to the onprem cluster.
Output:
Wait 30 seconds, then use nomos status
to see if Anthos Config Management is properly installed and configured. If the clusters aren't both synched, wait another 30 seconds and try again. They should be synched at this point.
Output:
Set your kubectl
context and list the Namespaces on the gke cluster:
List the ClusterRoles the gke cluster:
List the ClusterRolesBindings the gke cluster:
Describe the ClusterRoleBinding for namespace-readers:
Check the RoleBindings for the dev Namespace:
Check the RoleBindings for the prod Namespace:
Your configurations, stored in your Cloud Source Repository, have been applied to the gke cluster. Now, check to see if they have been applied to the onprem cluster.
Set your kubectl
context:
Repeat the steps that you performed against the gke cluster. Verify that the changes have applied to the onprem cluster as well.
In this task, you verify that Anthos Config Management keeps objects in sync with the configs in your repo, even if someone makes manual changes.
You are going to configure three Cloud Shell panes so that you can issue commands in one pane and watch the effects on the two clusters in the other panes.
Split the session screen with the tmux
utility built-into Cloud Shell by typing <Ctrl>+b
, then %
. You should see 2 panes in the Cloud Shell.
Any time you interact with tmux
, you'll start with the <Ctrl>+b
combination, which signals a command to tmux
.
Switch to the left-hand pane by typing:
<Ctrl>+b
<left-arrow>
Resize the left-hand pane by doing the following:
<Ctrl>+b
to begin interaction with tmux:
to get a tmux command promptresize-pane -L 35
to make the left-hand pane narrowerYour panes should look like this:
Switch to the right-hand pane by typing:
<Ctrl>+b
<right-arrow>
In the right-hand pane, split the pane by typing:
<Ctrl>+b
%
You should now have 3 panes that are roughly the same width.
Switch the the left-hand pane (<Ctrl>+b
, <right-arrow>
), set the kubectl
context, and have kubectl
watch for changes to the ClusterRoleBinding for namespace-readers on the gke cluster:
Switch the the middle pane (<Ctrl>+b
, <right-arrow>
), set the kubectl
context and have kubectl
watch for changes to the ClusterRoleBinding for namespace-readers on the onprem
cluster:
Switch the the right-hand pane (<Ctrl>+b
, <right-arrow>
), and delete the ClusterRoleBinding on both clusters:
You should see two updates display in each of the panes where you are watching for object changes. One indicating the deletion of the object, and one showing the creation of the object to have the cluster comply with the defined config.
In the right-hand pane, confirm that the ClusterRoleBinding has been recreated on the gke cluster:
Output:
Repeat the process for the onprem cluster.
Switch to the left-hand pane (<Ctrl>+b
, <right-arrow>
), and cancel the kubectl
watch command by typing <Ctrl>+c
.
Start a new watch command, this time observing changes to the prod Namespace labels on the gke cluster, and display the Namespace config in detail:
Switch to the middle pane (<Ctrl>+b
, <right-arrow>
), and cancel the kubectl
watch command by typing <Ctrl>+c
.
Start a new watch command, this time observing changes to the prod Namespace labels on the onprem cluster, and display the Namespace config in detail:
Switch to the right-hand pane (<Ctrl>+b
, <right-arrow>
), and remove the env: prod label from the prod Namespaces on both clusters:
You should see two messages in each of the panes where you are watching for object changes. The first shows the labels on the namespace after the env:prod label is removed. The second shows the labels after it's been re-added.
In this task, you verify that Anthos Config Management updates managed objects when the configs in your repo change.
Switch to the left-hand pane (<Ctrl>+b
, <rigt-arrow>
), and cancel the kubectl
watch command by typing <Ctrl>+c
.
In the left pane, review the namespace-readers
ClusterRoleBinding
on the gke cluster:
Output:
Configure kubectl
to watch for changes to the subjects in this ClusterRoleBinding on the gke cluster:
Switch to the middle pane (<Ctrl>+b
, <right-arrow>
), and cancel the kubectl
watch command by typing <Ctrl>+c
.
In the middle pane, review the namespace-readers
ClusterRoleBinding on the oprem cluster:
Output:
Configure kubectl
to watch for changes to the subjects in this ClusterRoleBinding on the onprem cluster:
Switch to the right-hand pane (<Ctrl>+b
, <right-arrow>
), and clear the pane:
Using the Cloud Shell Code Editor, edit the configuration file for the ClusterRoleBinding:
Add a new User block to the subjects
field for jane@anthos_labs.com
. You can copy the entire cheryl@anthos_labs.com
User, to a new User, and replace the name with jane@anthos_labs.com
.
The new subjects block has the contents:
Save your changes.
In the right pane, check your config changes are syntactically valid:
No errors are printed, so the configuration is valid.
In the right pane, create a commit, and push the change to your repo:
Within a few seconds of the push being completed, you should see a message in each of the panes where you are watching for object changes. They should show that there are now entries for both Cheryl and Jane.
In this lab, you configured Anthos Config Management and explored some of its useful features. You connected a Git repository for configuration-as-code change-management. You set up a Config Operator to manage your clusters, and you verified that the operator maintains state in your clusters to match your repository.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one