github.com/googlecloudplatform/kubernetes-workshops@v0.0.0-20180501174420-d8199445b2c3/bundles/kubernetes-101/workshop/labs/creating-and-managing-pods.md (about)

     1  # Creating and managing pods
     2  
     3  At the core of Kubernetes is the Pod. Pods represent a logical application and hold a collection of one or more containers and volumes. In this lab you will learn how to:
     4  
     5  * Write a Pod configuration file
     6  * Create and inspect Pods 
     7  * Interact with Pods remotely using kubectl
     8  
     9  In this lab you will create a Pod named `monolith` and interact with it using the kubectl command line tool.
    10  
    11  ## Tutorial: Creating Pods
    12  
    13  Explore the `monolith` pod configuration file:
    14  
    15  ```
    16  cat pods/monolith.yaml
    17  ```
    18  
    19  Create the `monolith` pod using kubectl:
    20  
    21  ```
    22  kubectl create -f pods/monolith.yaml
    23  ```
    24  
    25  ## Exercise: View Pod details
    26  
    27  Use the `kubectl get` and `kubectl describe` commands to view details for the `monolith` Pod:
    28  
    29  ### Hints
    30  
    31  ```
    32  kubectl get pods
    33  ```
    34  
    35  ```
    36  kubectl describe pods <pod-name>
    37  ```
    38  
    39  ### Quiz
    40  
    41  * What is the IP address of the `monolith` Pod?
    42  * What node is the `monolith` Pod running on?
    43  * What containers are running in the `monolith` Pod?
    44  * What are the labels attached to the `monolith` Pod?
    45  * What arguments are set on the `monolith` container?
    46  
    47  ## Exercise: Interact with a Pod remotely
    48  
    49  Pods are allocated a private IP address by default and cannot be reached outside of the cluster. Use the `kubectl port-forward` command to map a local port to a port inside the `monolith` pod. 
    50  
    51  ### Hints
    52  
    53  Use two terminals. One to run the `kubectl port-forward` command, and the other to issue `curl` commands.
    54  
    55  ```
    56  kubectl port-forward monolith 10080:80
    57  ```
    58  
    59  ```
    60  curl http://127.0.0.1:10080
    61  ```
    62  
    63  ```
    64  curl http://127.0.0.1:10080/secure
    65  ```
    66  
    67  ```
    68  curl -u user http://127.0.0.1:10080/login
    69  ```
    70  
    71  > Type "password" at the prompt.
    72  
    73  ```
    74  curl -H "Authorization: Bearer <token>" http://127.0.0.1:10080/secure
    75  ```
    76  
    77  > Use the JWT token from the previous login.
    78  
    79  ## Exercise: View the logs of a Pod
    80  
    81  Use the `kubectl logs` command to view the logs for the `monolith` Pod:
    82  
    83  ```
    84  kubectl logs monolith
    85  ```
    86  
    87  > Use the -f flag and observe what happens.
    88  
    89  ## Exercise: Run an interactive shell inside a Pod
    90  
    91  Use the `kubectl exec` command to run an interactive shell inside the `monolith` Pod:
    92  
    93  ```
    94  kubectl exec monolith --stdin --tty -c monolith /bin/sh
    95  ```