Skip to content

Lab 1 : Connect to a Kubernetes Cluster

Boskey Savla edited this page Aug 25, 2019 · 9 revisions

Welcome to the Run Kubernetes with VMware workshop wiki!

The wiki has instructions for the Hands on exercises that will be conducted during the Workshop. We will be using VMware Cloud PKS for the labs. VMware Cloud PKS already has Kubernetes clusters pre-provisioned for this workshop. You have been assigned to a pre-provisioned cluster in Cloud PKS. The clusters will be available 24 hours after the workshop if you need to continue working on them.

Lab 1: Setup/Configuration

1. Register/Login to Cloud PKS

  • By now you should have an invitation email to login to VMware Cloud PKS, please follow instructions in the email to sign-up as a user for VKE
  • In order to register, you will need to have a login in 'My VMware'. If you already have a login in 'My VMware' using the same email address you used for registration you don't have to create a new one. Else, you will be directed to create a 'My VMworld' ID.
  • One of the Proctors for the Workshop should have assigned you a Kubernetes Cluster that's already pre-created and assigned to you, please have the cluster name handy. ( It's on the note you got!)
  • If you haven't received the invitation email or do not know the name of the Kubernetes Cluster assigned to you, please reach out to one of the proctors.

2. Download Cloud PKS CLI and Kubectl

The CLoud PKS(VKE) CLI will help us interact with the platform, fetch us the tokens needed to get authenticated access to the Kubernetes cluster

Procedure

  1. In a browser, launch the VMware Cloud Services console. https://console.cloud.vmware.com/
  2. Log in to your VMware Cloud services organization.
  3. On the VMware Cloud PKS tile, click Open. This takes you to the Cloud PKS console.
  4. Click on 'Developer Center', once there click the text 'DOWNLOAD THE VMWARE CLOUD PKS CLI'. Click on 'Downloads' and select the version based on the operating system you are working on.

NOTE: The Cloud PKS CLI is called 'vke' ( The product was originally called VKE)

  1. Also on the same page, download kubectl by clicking the download button under the kubectl tile.
  2. After the download completes, move the vke executable to a common bin directory (for example, ~/bin or %UserProfile%\bin).
  • For Linux or Mac OS X: % mkdir ~/bin % cp vke ~/bin
  • For Windows: mkdir %UserProfile%\bin copy vke.exe %UserProfile%\bin
  1. Make sure your bin directory is accessible on your PATH.
  • For Linux or Mac OS X: % export PATH=$PATH:/Users/your-user-name/bin
  • For Windows: set PATH=%PATH%;%UserProfile%\bin
  1. Make the file executable.
  • For Linux or Mac OS X: % chmod +x ~/bin/vke
  • For Windows: attrib +x %UserProfile%\bin\vke.exe
  1. Now change to a different directory and check the version to verify that the CLI is ready to use. vke --version

Kubectl is a command line interface for Kubernetes, it lets you interact with the Kubernetes cluster. Once logged in to the cluster Kubectl will be used anytime you want to deploy apps/services/provision storage etc. or need to query the cluster for existing pods/nodes/apps/services etc.

Once downloaded, save the file in your environment for you to be able to access it from any directory. Just like the vke CLI above.

You can also interact with Kubernetes using the kubernetes dashboard if you prefer UI over CLI, the Kubernetes dashboard is available from the Cloud PKS console-->Your-Cluster-Name>-->Actions-->Open K8's UI

3. Login to Cloud PKS via vke CLI

So far we have downloaded the Cloud PKS CLI and kubectl CLI, now we will login to Cloud PKS via the CLI to fetch the access tokens needed to talk to the clusters

Get access to the Organization ID and Refresh Tokens

  1. Go back to the Cloud PKS web interface Click on 'Developer Center' and click the Overview tab, once there you will see the CLI to login to Cloud PKS with the organization ID , copy the entire command like and store it in a note pad.

  2. On the same page, click on 'Get your Refresh Token', this will redirect the browser to the 'My Accounts' page and you will see your OAuth Refresh Token, copy the token. If there is no token click "Generate Key" and copy it. Save the 'refresh token'

Please treat this Refresh Token as your Password and DO NOT SHARE it with others

Login using the Organization ID and Refresh Token

  1. Login to Cloud PKS, copy paste the login command from above (step1) and replace 'your-refresh-token' with the one you retrieved above (step 2)(omit the quotes).

vke account login -t 'your-organization-id' -r 'your-refresh-token'

  1. Set folder and project within VKE

vke folder set SharedFolder

vke project set SharedProject

  1. Fetch Kubectl auth for your cluster, replace with the name of the cluster assigned to you in the command below

This will fetch the authentication token for your cluster and store it in your ~./kubeconfig file. The access token is what helps us authenticate against the cluster.

vke cluster merge-kubectl-auth <your-cluster-name>

5. Access Kubernetes Cluster via Kubectl

You should now be able to interact with your cluster using kubectl, give kubectl a try, run below commands to see your cluster Pods and Services

  • kubectl get pods - Fetches the pods currently deployed in the cluster.
  • kubectl get svc - Fetches the various services currently created in the cluster.

6. View Kubernetes Resources

Kubernetes can be accessed using CLI (kubectl) or the Kubernetes Dashboard(UI). Let's take a look at the Dashboard to see how various object/resources are created in the cluster to support

  1. Create a new Deployment

Login to VMware Cloud PKS Console--> Click on Smart Clusters in the LHS menu --> Click on your Cluster Name --> Actions --> Open K8s UI (Tip: Use the search filter on the name field to find your cluster)

You will be in the default Namespace.

Click 'Deployments' in the Left Hand Side Navigation Bar. Then Click on the * + Create* button on the top RHS of the page.

Click on the tab 'Create an App'

Give the following inputs

  • App Name: nginx
  • Container Image: nginx
  • Number of Pods: 2
  • Service: Internal
  • Port: 80
  • Target Port: 8080

Click Deploy

This will Deploy Nginx, an http Proxy server. (tip: Wait a few seconds to refresh the page)

Wait for a few seconds and refresh the page. Observe the various Kubernetes objects that were created for this Deployment by clicking on 'Pods', 'Deployments', 'Services', 'Replica Sets' etc. in the LHS Menu.

You will see:

  • 1 Deployment Resource created for app 'Nginx'
  • 2 Pods created with nginx Containers in it since we asked Kuebrnetes do Deploy 2 instances
  • 1 Replica sets that makes sure there are always 2 instances of the pod nginx running
  • 1 Service that ensures other pods running in the cluster can access nginx ( Internal only)