Month: July 2023

  • [บันทึกกันลืม] วิธีกำหนดให้ pod สร้างเฉพาะบน node ที่ต้องการ

    Kubernetes cluster สามารถกระจายตัวไปในหลาย ๆ ดาต้าเซนเตอร์ได้ แต่ในบางงาน เช่น การใช้ Airflow ในการเข้าถึงข้อมูลบนระบบฐานข้อมูล ซึ่งจำกัดการเข้าถึงได้เฉพาะจากบาง IP range เท่านั้น สามารถทำได้โดยการกำหนด ‘label’ ให้ nodes ที่ต้องการ และ nodeSelector ของ pods หรือ resources

    วิธีกำหนด label ให้ node

    ใช้คำสั่งต่อไปนี้ เพื่อ label ว่า ‘database-access=true’ ให้ node ชื่อ ‘dc1node1’ ซึ่งเป็น node ที่สามารถเข้าถึงฐานข้อมูลได้

    kubectl label node/dc1node1 database-access=true

    วิธีระบุ Pod/Resource ให้เลือก node ที่ต้องการ

    ใช้คำสั่งเพื่อ edit เช่น

    kubectl edit statefulset.apps/airflow-worker -n airflow

    จากนั้นเลื่อนไปที่

    spec: containers: initContainers: nodeSelector:

    ตั้งค่า

    database-access: "true"

    เมื่อทำมีการ reschedule ก็จะไปใช้ node ที่มี label ตามที่กำหนด

    หวังว่าจะมีประโยชน์ครับ

  • [บันทึกกันลืม] วิธีเพิ่ม Node (Ubuntu 22.04) เข้า Kubernetes cluster (version 1.25.0)

    Adding a new node running Ubuntu 22.04 to Kubernetes version 1.25.0 cluster.

    swapoff -a
    sed -i 's/\/swap.img/#\/swap.img/g' /etc/fstab
    echo 1 > /proc/sys/net/ipv4/ip_forward
    modprobe overlay
    modprobe br_netfilter
    sysctl --system
    apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    apt update -y
    apt install -y containerd
    mkdir /etc/containerd
    containerd config default > /etc/containerd/config.toml
    sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
    systemctl restart containerd
    systemctl enable containerd
    apt -y install curl vim git wget apt-transport-https gpg
    mkdir /etc/apt/keyrings
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.25/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
    echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.25/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
    apt update -y
    apt install -y  kubelet=1.25.16-1.1 kubeadm=1.25.16-1.1
    apt-mark hold kubelet kubeadm kubectl
    systemctl enable kubelet
    kubeadm join <IP>:6443 --token <TOKEN> --discovery-token-ca-cert-hash sha256:<SHA256>

    Hope this help.

  • [บันทึกกันลืม] ย้าย docker ไปไว้ที่ partition อื่น

    ปัญหา

    ถ้าติดตั้ง docker บน Linux โดยค่าเริ่มต้นจะสร้างที่เก็บพวก image, container และ volumns ต่าง ๆ ไว้ที่ /var/lib/docker เมื่อใช้งานไปเรื่อย ๆ จะทำให้ / เต็ม

    วิธีการแก้ไข

    ควร mount disk partition ใหม่นอก / เข้ามา เช่น ‘/otherpartition’ จาก disk อีกลูก แล้วสร้างไดเรคทอรี่ ‘docker’ แล้ว copy ข้อมูลทั้งหมดจาก /var/lib/docker ไปยัง /otherpartition/docker

    rsync  -apv /var/lib/docker /otherpartition/docker

    จากนั้นสร้างไฟล์

    /etc/docker/daemon.json
    { 
       "data-root": "/otherpartition/docker" 
    }

    จากนั้น restart docker

    systemctl restart docker

    หวังว่าเป็นประโยชน์