Note - Kubernetes in Action

I took notes during reading “Kubernetes in Action”.

It can be found on Amazon.

Part 1: Overview

Part 2: Core concepts

Chapter 3:

  • Po/pods/pod is similar. For example:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    kubectl get po
    kubectl get pod
    kubectl get pods
    ```
    It's the same with service/services.

    ### Introducing pods

    **A pod** is a Kubernetes abstraction that represents a group of one or more application containers (such as Docker or rkt), and some shared resources for those containers. You can have several related docker containers run on a pod.

    A Pod always runs on a Node. **A Node** is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster.

    #### Create pod with yaml/json
    - Create pod from yaml file

kubectl create -f [yaml/json file]

1
- Get a list of pods

kubectl get po

1
- Get describes of pods

kubectl get po [pod_name] -o yaml

1
- Get log of container (-c is optional, when you want to view the log of a specific container)

kubectl logs [pod_name] -c [container_name]

1
- Forward port 80 from pod to port 8888 local (effective way to test pod)

kubectl port-forward [pod_name] 8888:80

1
2
3
4
5

### Organizing resources with labels
- Label is an arbitrary key-value attached to a resources. It can be defined under metadata.labels tag.
- Each pod is recommended to be labeled with 2 labels: app (which microservice it belong to), env (which environment: staging, dev,..)
- Get the list of pods with label

kubectl get po –show-labels

1
- Get the pods with specific label by column (in this case is app & rel)

kubectl get po -L app,rel

1
- Get the pods with label selector

///Get the pods have env label
kubectl get po -l env
///Get the pods have specific env label
kubectl get po -l env=staging

1
- Change label of pods

kubectl label po [pod_name] app=frontend
kubectl label po [pod_name] –overwrite app=backend

1
2
3
4
5
6

#### Constrain pod scheduling with labels and selectors

All the pods is scheduled randomly across the worker nodes by default.

- Add the label to specific nodes

//get list of nodes
kubectl get nodes –show-labels
//add the label
kubectl label node [node_name] gpu=true

1
- Schedule pods to specific nodes which have gpu label is ```true``` by editing in yaml/json file. Should do like this instead of scheduling to a specific node because the node can be offline.


spec:
nodeSelector:
gpu: “true”

1
2
### Annotation
Mostly the same with label. But annotation is used for large blobs of data (256KB in total); mostly use of annotations is adding descriptions for each pod.

kubectl annotate pod [pod_name] mycompany.com/someannotation=”this pos is used for…”
```

Namespaces

Share 0 Comments