티스토리 뷰

Infra/Kubernetes

About Pod

Jordy-torvalds 2019. 10. 27. 14:00

Specific Pod`s Full YAML

kubectl get po jordi-4bxm8 -o yaml

Specific Pod`s Full JSON

kubectl get po jordi-4bxm8 -o json

Pod`s separate Fields Information

kubectl explain pods

Pod`s detailed fields Information

kubectl explain pod.spec

Examples of YAML file.

apiVersion: v1
kind: Pod
metadata:
    name: kubia-manual-test
spec:
    containers:
    -   image: bearstark/jordi
        name: jordi
        ports:
        -   containerPort: 8080
            protocol: TCP

Create a Pods using YAML.

kubectl create -f <yaml file dir.>

Check a specific Pod`s Log

kubectl logs <pods id>`

kubectl logs <pods id> -c <containers id>

When a request is received, a command about turning over toward specific ports.

kubectl port-forwarding <pods id> `

Examples of YAML file included labels

apiVersion: v1
kind: Pod
metadata:
    name: kubia-manual-v2
    labels:
        creation_method: manual
        env: prod
spec:
    containers:
    -   image: bearstark/jordi
        name: jordi
        ports:
        -   containerPort: 8080
            protocol: TCP

After Creating a Pod, Checking a label of pods

kubectl get po --show-labels

kubectl get po -L creation_method,env

Modifing labels of existing pods

kubectl label pods <name of pods> <sort of label>=<content of label>

ex > kubectl label po kubia-manual creation_method=manual

Overwriting labels of Existing Pods

kubectl label po <name of pods> <sort of label>=<content of label> --overwrite

  • 예시

kubectl label po kubia-manual-v2 env=debug --overwrite

Listing a pods using label selector

Value Comparison

kubectl get po -l <sort of label>=<content of label>

kubectl get po -l <sort of label>!=<content of label>

Specific Categorization

kubectl get po -l env

ex> kubectl get po -l creation_method=manual

Denially Specific Categorization

kubectl get po -l '!env'

In Comparision

kubectl get po -l env in (prod, devel)

kubectl get po -l env notin (prod, devel)

Multi Conditions of In Comparision

kubectl get po -l env in (prod, devel),creation_method=manual

kubectl get po -l env notin (prod, devel),creation_method=manual

Config Label to Nodes

kubectl label node <node name> <sort of label>=<value of label>

예시

kubectl label node gke-jordi-default-pool-08313642-c93c gpu=true

Listing a Nodes using Label Selector

kubectl get nodes -l gpu=true

Listing a pods with detailed information and sorting

kubectl get pods -o wide --sort-by="{.spec.nodeName}"

Listing a pods with detailed information

kubectl get pods -o wide

Differences between label and annotation

Annotation is not for Identifying Informations.

Annotation can`t groups objects.

Annotation is not a selector.

Annotation can hlod much larger pieces of information.

Annotation primarily differentiate versions of Objects.

ex) alpha, beta, deprecated etc..

Label is for Identifying Informations.

Label can groups objects.

Label is a selector.

Config a Annotation to specific Pods

kubectl annotate pod kubia-manual [jorid.com/annotation="cute"](http://jorid.com/annotation=%22cute%22)

Check a Annotation of pods

kubectl describe po kubia-manual

About Namespaces(ns)

Necessity

  1. 개발, 운영, 테스트 등으로 나눠진 복잡한 시스템은 여러 구성요소들로 구성되어져 있다.
  2. 그 구성요소들을 분명하게 작은 그룹으로 나누어준다.
  3. 중복이 많은 Label과 달리, 특정 네임스페이스 내에 자원들에 중복이 없다.

Definition

  1. 수 많은 구성요소, 객체들을 명확히 나누어 주는 역할.
  2. In Namespace, Object is not overlapping. So 'resource name' can`t be not same between objects in namespace.

Methods(Commands)

Listing Namespaces(ns)

kubectl get ns

Listing Pods In specific Namespaces

kubectl get po --namespace kube-system

kubectl get po -n kube-system

Examples of Yaml for Creaing Namespace

apiVersion: v1
kind: Namespace
metadata:
    name: custom-namespace
# kubectl create -f <this-file-name>

Commands for Creating Namespace

kubectl create ns custom-namespace

Creating a pod in specific Namespace

kubectl create -f kubia-manual.yaml -n custom-namespace

Listing a pods in all namespaces

kubectl get pods --all-namespaces

Modifying Default Namespace

kubectl config set-context --current --namespace=default

Setting Alias for Modeling Default Namespace

alias kcd='kubectl config set-context $(kubectl config current-context) --namespace'

What is $()?

print out a result of .

Network Isolation

Basically each pods network that belong to other group are isolated each other.

But, Depending on network isolation settings, communication availability will be decided.

Deleting a pod

kubectl delete po <pods name>`

kubectl delete po -l <sort of label>=<value of label>

kubectl delete ns <namespacea name>`

kubectl delete po --all

Deleting all objects

kubectl delete all --all

but the command can`t delete all of object absolutely.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함