👤
Novice Handbook
  • Novice Handbook
  • Guide
  • Internet และ Web
    • HTML
  • Computer Language
    • Basic Computer Language (LV.1)
    • C Language (LV.1)
    • Python3 (LV.1)
  • Operating System
    • Linux
      • Basic Linux (LV.1)
  • TOOLS
    • Text Editor
      • Vim Editor
    • Source Control
      • GitLab
        • GitLab for small site (LV.1)
    • Container
      • Docker
        • Docker (LV.1)
        • Docker (LV.2)
      • Kubernetes
        • Kubernetes Intro (LV.0)
        • Kubernetes Basic (LV.1)
        • Kubernetes Intermediate (LV.2)
        • Helm (LV.2)
        • RKE2 (LV.3)
        • K3S (LV.3)
        • K3D (LV.3)
    • Repository
      • Harbor
        • Harbor for small site (LV.1)
        • Harbor for enterprise (LV.2)
    • Database
      • Redis
        • Redis on Docker Compose (LV.1)
        • Redis on Kubernetes (LV.2)
      • Elastic Stack
        • Elasticsearch & Kibana for small site (LV.1)
    • Observability
      • Prometheus
        • Prometheus for small site (LV.1)
        • Prometheus Operator (LV.2)
    • Security
      • Certbot (LV.1)
      • Falco
      • Hashicorp Vault
    • Collaboration
      • Nextcloud
Powered by GitBook
On this page
  • Setup
  • Usage
  • K3D with cilium
  • reference:

Was this helpful?

  1. TOOLS
  2. Container
  3. Kubernetes

K3D (LV.3)

k3d ถูกสร้างขึ้นเพื่อเป็นเครื่องมือที่ช่วยให้สามารถรัน k3s ภายในคอนเทนเนอร์ Docker โดยมีวัตถุประสงค์หลักเพื่อทำให้การจัดการและการใช้งานคลัสเตอร์ของ K3s เป็นไปอย่างง่ายดายและรวดเร็ว โดยเฉพาะอย่างยิ่งสำหรับสภาพแวดล้อมการพัฒนาและการทดสอบในเครื่อง

k3d เป็นเครื่องมือที่จำลอง k3s cluster ภายใน Docker container มีวัตภุประสงค์เพื่อให้ง่ายต่อการสร้างและจัดการ Kubernetes cluster ซึ่งใช้ในการทดสอบภายในเครื่องของ Developer เอง

ประโยชน์หลักของ k3d มีดังนี้

  1. การพัฒนาในเครื่อง (Local Development): k3d ช่วยให้นักพัฒนาสามารถสร้างคลัสเตอร์ Kubernetes บนเครื่องของตัวเองได้ง่าย ๆ โดยใช้ Docker ทำให้สามารถพัฒนาและทดสอบแอปพลิเคชันที่ใช้ Kubernetes โดยไม่จำเป็นต้องใช้ Infrastructure บนคลาวด์หรือเซิร์ฟเวอร์จำนวนมาก

  2. ความเรียบง่าย (Simplicity): เนื่องจาก K3s เป็น Kubernetes ที่ออกแบบมาให้มีขนาดเล็กอยู่แล้ว k3d ช่วยทำให้กระบวนการสร้างและจัดการคลัสเตอร์ Kubernetes ภายใน Docker นั้นง่ายยิ่งขึ้น ลดความซับซ้อนและขั้นตอนที่เกี่ยวข้องกับการจัดการ Kubernetes สำหรับการพัฒนาและทดสอบ

  3. ความรวดเร็ว (Speed): การติดตั้งคลัสเตอร์ Kubernetes แบบเต็มรูปแบบอาจใช้เวลานานและต้องการทรัพยากร แต่ด้วย k3d คุณสามารถสร้างคลัสเตอร์ Kubernetes ที่พร้อมใช้งานได้ภายในไม่กี่วินาที ซึ่งเหมาะสำหรับการสร้างสภาพแวดล้อมการทดสอบหรือการทดลองฟีเจอร์ต่าง ๆ ของ Kubernetes อย่างรวดเร็ว

  4. คลัสเตอร์แบบหลายโหนด (Multi-Node Clusters): k3d ช่วยให้ผู้ใช้สามารถสร้างคลัสเตอร์ที่มีหลายโหนด (Node) ได้ ซึ่งเป็นการจำลองสภาพแวดล้อม Kubernetes ที่มีหลายโหนดเหมือนในโลกความเป็นจริง ทั้งหมดนี้รันอยู่ในคอนเทนเนอร์ Docker บนเครื่องเดียว

  5. ประหยัดค่าใช้จ่าย (Cost-Effective): การรัน Kubernetes ในคอนเทนเนอร์ Docker บนเครื่องช่วยหลีกเลี่ยงค่าใช้จ่ายที่เกี่ยวข้องกับการรันคลัสเตอร์ Kubernetes บนผู้ให้บริการคลาวด์ในระหว่างการพัฒนาและทดสอบ

สรุปแล้ว k3d ถูกใช้หลัก ๆ สำหรับการพัฒนาและทดสอบ Kubernetes ในเครื่อง โดยมอบสภาพแวดล้อมที่รวดเร็ว กิน resource น้อย และใช้งานง่าย ทำให้นักพัฒนาสามารถทดสอบและพัฒนาได้อย่างรวดเร็วโดยไม่ต้องใช้ Infrastructure ขนาดใหญ่

Setup

curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash

Usage

create cluster

k3d cluster create mycluster

หรือ

k3d cluster create --agents 3 mycluster

add agent node

k3d node create agent-node --cluster mycluster

list node

k3d node ls

remove node

kubectl drain k3d-agent-node-0 --ignore-daemonsets
kubectl delete node k3d-agent-node-0
k3d node delete k3d-agent-node-0

delete cluster

k3d cluster delete mycluster

Expose Loadbalancer port

k3d cluster edit --port-add 8080:80@loadbalancer mycluster

command นี้จะเปิด port 8080 บนเครื่อง host ไปยัง loadbalancer node ของ cluster mycluster port 80


K3D with cilium

เตรียม config file ชื่อ k3dconfig.yaml ดังนี้

apiVersion: k3d.io/v1alpha5
kind: Simple
metadata:
  name: cilium-test
servers: 1
agents: 2

ports:
  - port: 8080:80
    nodeFilters:
      - loadbalancer
  - port: 8443:443
    nodeFilters:
      - loadbalancer

options:
  k3s:
    extraArgs:
      - arg: --disable=traefik
        nodeFilters:
          - server:*
      - arg: --disable-network-policy
        nodeFilters:
          - server:*
      - arg: --flannel-backend=none
        nodeFilters:
          - server:*

สร้าง cluster ด้วยคำสั่งดังนี้

k3d cluster create --config k3dconfig.yml

custom k3d node เพื่อให้รองรับ cilium (*ใช้กับกรณี k3s/k3d เท่านั้น)

docker exec -it k3d-cilium-test-server-0 mount bpffs /sys/fs/bpf -t bpf && \
    docker exec -it k3d-cilium-test-server-0 mount --make-shared /sys/fs/bpf
docker exec -it k3d-cilium-test-agent-0 mount bpffs /sys/fs/bpf -t bpf && \
    docker exec -it k3d-cilium-test-agent-0 mount --make-shared /sys/fs/bpf
docker exec -it k3d-cilium-test-agent-1 mount bpffs /sys/fs/bpf -t bpf && \
    docker exec -it k3d-cilium-test-agent-1 mount --make-shared /sys/fs/bpf

ติดตั้ง cilium

helm install cilium cilium/cilium \
	--namespace kube-system \
	--set hostServices.enabled=false \
	--set externalIPs.enabled=true \
	--set nodePort.enabled=true \
	--set hostPort.enabled=true \
	--set bpf.masquerade=false \
	--set image.pullPolicy=IfNotPresent \
	--set ipam.mode=kubernetes \
	--set kubeProxyReplacement=strict

reference:

PreviousK3S (LV.3)NextRepository

Last updated 5 months ago

Was this helpful?

Cilium installation failing in K3D cluster · Issue #23237 · cilium/ciliumGitHub
Running Cilium in K3S and K3D (lightweight Kubernetes) on Mac OS for developmentSandstorm - Wir programmieren Zukunft.
Logo
Logo