Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shriomtri/8b3ab017e60e7f5a64e08dde008b34f0 to your computer and use it in GitHub Desktop.
Save shriomtri/8b3ab017e60e7f5a64e08dde008b34f0 to your computer and use it in GitHub Desktop.
Exploring a Kubernetes Cluster with kubectl

Exploring a Kubernetes Cluster with kubectl

Introduction

kubectl is the primary interface most people use in order to work with Kubernetes. This lab will give you a chance to test and hone your kubectl skills with a real Kubernetes cluster. You will have the opportunity to collect information and make changes to the cluster, all using kubectl.

Additional Resources

You are working for BeeBox, a company that provides regular shipments of bees to customers. The company is in the process of building a Kubernetes-based infrastructure for some of their software.

You have several work tickets that will need to be addressed by using kubectl to interact with the Kubernetes cluster. You will need to collect some information from the cluster and save that information in some files for later review. You will also need to make some changes to the cluster.

Solution

Log in to the provided lab server using the credentials provided:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Get a List of Persistent Volumes Sorted by Capacity

  1. Get a list of persistent volumes sorted by capacity:

    kubectl get pv
    
    
    kubectl get pv -o yaml
    
    
    kubectl get pv --sort-by=.spec.capacity.storage
    
    
  2. Save the list to a file:

    kubectl get pv --sort-by=.spec.capacity.storage > /home/cloud_user/pv_list.txt
    
    
  3. List the contents of the file to verify it saved:

    cat pv_list.txt
    
    

Run a Command Inside the quark Pod's Container to Obtain a Key Value

  1. Get the contents of a file from inside the quark pod's container:

    kubectl exec quark -n beebox-mobile -- cat /etc/key/key.txt
    
    
  2. Save it to a file:

    kubectl exec quark -n beebox-mobile -- cat /etc/key/key.txt > /home/cloud_user/key.txt
    
    
  3. List the contents of the file to verify it saved:

    cat key.txt
    
    

Create a Deployment Using a Spec File

  1. Create a deployment using the deployment spec found in /home/cloud_user/deployment.yml:

    kubectl apply -f /home/cloud_user/deployment.yml
    
    
    kubectl get deployments -n beebox-mobile
    
    
    kubectl get pods -n beebox-mobile
    
    

Delete the beebox-auth Service

  1. Delete beebox-auth-svc:

    kubectl delete service beebox-auth-svc -n beebox-mobile
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment