Module 2: Introduction to Kubernetes
This exercise focuses on enabling you to do the following:
-
Explore the Kubernetes cluster and configuration
-
Communicate with the Kubernetes cluster via CLI and API
-
Upgrade your Kubernetes cluster
NOTE: All the tasks in the following module are executed on the Kubernetes Master node (rhel3). You must SSH the rhel3 host in your labs. Task 1 will show you how to copy the kubeconfig file to the Windows jump host, in order to be able to execute the kubectl commands from PS or CMD.
In this task, you will explore the Kubernetes Cluster Configuration, create a user, and install kubectl on Windows.
Step | Action |
---|---|
![]() |
|
![]() |
|
Using Putty, open an SSH connection to rhel3, your Kubernetes master node: |
|
Review the available options in kubectl: kubectl --help |
|
Make sure autocompletion is enabled for kubectl: source <(kubectl completion bash) |
|
Review the Kubernetes configuration: kubectl config view If you use multiple kubeconfig files at the same time and you want to merge the views: KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view |
|
Get the Kubernetes version in json or yaml format: kubectl version -o json (or -o yaml) |
|
Create a new Kubernetes service account called rouser (Read-Only User): kubectl create serviceaccount rouser |
|
Create a cluster role called rouser: kubectl create clusterrole rouser --verb=get --verb=list --verb=watch --resource=pods |
|
Create a cluster role binding: kubectl create clusterrolebinding rouser --serviceaccount=default:rouser --clusterrole=rouser |
|
Now get the token from secret of ServiceAccount we have created before. we will use this token to authenticate user: TOKEN=$(kubectl describe secrets "$(kubectl describe serviceaccount rouser | grep -i Tokens | awk '{print $2}')" | grep token: | awk '{print $2}') |
|
Now set the credentials for the user in kube config file. We will use “learner” as a username: kubectl config set-credentials learner --token=$TOKEN |
|
Now we will have to create a new context for the user. We will call it “reader”. Our Cluster is called “Kubernetes” (refer to step 1-4): kubectl config set-context reader@kubernetes --cluster=kubernetes --user=learner |
|
Review the Kubernetes contexts: kubectl config view |
|
Switch to the newly created context: kubectl config use-context reader@kubernetes |
|
Notice that the current-context has changed to reader@kubernetes: kubectl config view |
|
![]() |
|
Verify that the user has the right privileges: kubectl auth can-i get pods --all-namespaces (should be yes) kubectl auth can-i create pods (should be no) kubectl auth can-i delete pods (should be no) |
|
Switch back to the default administrator context: kubectl config use-context kubernetes-admin@kubernetes |
|
Check the privileges and compare: kubectl auth can-i get pods --all-namespaces kubectl auth can-i create pods kubectl auth can-i delete pods |
|
![]() |
|
Let’s start by installing kubectl on your jump host. Open the Chrome web browser. | |
Within Chrome, enter: http://storage.googleapis.com/kubernetes-release/release/v1.5.3/bin/windows/amd64/kubectl.exe | |
After you download the folder, move to a new directory: C:\kube | |
Using the Windows search to locate the Control Panel. Select System. Select Advanced system settings. Select Environment Variables. Add C:\kube to your PATH environment variable. | |
Verify the installation and the version at a command prompt: kubectl version --client -o json |
|
Verify the kube config: kubectl config view Note that it is empty. This is because the automated script configuration didn’t detect the host as being a master node. |
|
Create a new folder called kube under your home directory (C:\Users\Administrator.DEMO): mkdir .kube |
|
Using WinSCP or copy/paste, transfer the “config” file from $HOME/.kube/config on the rhel3 master node to the newly created .kube folder on your windows jump host: |
|
Now go back to the command prompt and type: kubectl get nodes You have now successfully created a management host for one or multiple Kubernetes clusters. |
|
Start a Web proxy on the default port 8001: kubectl proxy |
|
Verify that the connection is working properly and that you can access the Kubernetes APIs. Using Chrome, browse the URL http://127.0.0.1:8001. Explore more on your own. |
In this task, you will learn how to upgrade the Kubernetes software components using the kubeadm command.
End of Exercise