반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- nginx ingress
- Model Serving
- tekton
- kubernetes operator
- opensearch
- Argo
- Kubeflow
- keda
- Kubernetes
- seldon core
- blue/green
- Continuous Deployment
- Kubernetes 인증
- 카오스 엔지니어링
- MLflow
- Litmus
- mlops
- gitops
- operator
- Kopf
- Pulumi
- serving
- opentelemetry
- 오퍼레이터
- argocd
- CANARY
- eBPF
- xdp
- knative
- CI/CD
Archives
- Today
- Total
Kubernetes 이야기
BuildKit 빌드 본문
반응형

buildkit으로 이미지 빌드 후 K8S에 배포하는 방법에 대해 알아보자. 핵심은 BuildKit 데몬을 클러스터 내에 띄우고, buildctl 클라이언트로 빌드를 트리거한 뒤, 빌드된 이미지를 private registry에 push하고, 그 이미지를 참조하는 Pod를 배포하는 흐름이다.
1. BuildKit 데몬 배포 (rootless, StatefulSet)
apiVersion: v1
kind: ServiceAccount
metadata:
name: buildkit
namespace: build-system
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: buildkitd
namespace: build-system
spec:
serviceName: buildkitd
replicas: 2 # 동시 빌드 처리량에 맞춰 조정
selector:
matchLabels:
app: buildkitd
template:
metadata:
labels:
app: buildkitd
annotations:
container.apparmor.security.beta.kubernetes.io/buildkitd: unconfined
container.seccomp.security.alpha.kubernetes.io/buildkitd: unconfined
spec:
serviceAccountName: buildkit
containers:
- name: buildkitd
image: moby/buildkit:v0.13.2-rootless
args:
- --addr
- unix:///run/user/1000/buildkit/buildkitd.sock
- --addr
- tcp://0.0.0.0:1234
- --oci-worker-no-process-sandbox
readinessProbe:
exec:
command: ["buildctl", "debug", "workers"]
initialDelaySeconds: 5
periodSeconds: 30
livenessProbe:
exec:
command: ["buildctl", "debug", "workers"]
initialDelaySeconds: 5
periodSeconds: 30
securityContext:
seccompProfile:
type: Unconfined
runAsUser: 1000
runAsGroup: 1000
ports:
- containerPort: 1234
volumeMounts:
- name: buildkitd
mountPath: /home/user/.local/share/buildkit
volumeClaimTemplates:
- metadata:
name: buildkitd
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 30Gi # 캐시 용량
---
apiVersion: v1
kind: Service
metadata:
name: buildkitd
namespace: build-system
spec:
selector:
app: buildkitd
ports:
- port: 1234
targetPort: 1234
clusterIP: None # headless, StatefulSet pod별 직접 접근
rootless를 권장하는 이유: privileged 컨테이너가 필요 없고 PSA(Pod Security Admission) restricted 네임스페이스에서도 동작 가능. 다만 OverlayFS가 fuse-overlayfs로 fallback되므로 빌드 속도는 약간 저하됨. 성능이 우선이라면 moby/buildkit:v0.13.2 (rootful) + securityContext.privileged: true로 변경.
2. Registry 인증용 Secret
kubectl -n build-system create secret docker-registry regcred \
--docker-server=harbor.registry.local \
--docker-username=builder \
--docker-password='****' \
--docker-email=kmaster8k@gmail.com
3. 빌드 Job (buildctl 클라이언트 + Git context)
apiVersion: batch/v1
kind: Job
metadata:
name: build-myapp-001
namespace: build-system
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: buildctl
image: moby/buildkit:v0.13.2-rootless
command: ["sh", "-c"]
args:
- |
buildctl \
--addr tcp://buildkitd-0.buildkitd.build-system.svc.cluster.local:1234 \
build \
--frontend=dockerfile.v0 \
--opt context=https://github.com/git/example-dockerfile-python.git#master \
--opt filename=Dockerfile \
--output type=image,name=harbor.registry.local/apps/helloworld:v1.0.0,push=true
env:
- name: DOCKER_CONFIG
value: /home/user/.docker
volumeMounts:
- name: docker-config
mountPath: /home/user/.docker
readOnly: true
volumes:
- name: docker-config
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: config.json
핵심 포인트:
- context=https://... — Git URL을 직접 전달하면 별도 sidecar로 clone할 필요 없음. 로컬 디렉터리를 보내려면 buildctl build --local context=. --local dockerfile=. 패턴 사용 (이 경우 kubectl exec 또는 stdin 스트리밍 필요).
- output=type=image,push=true — 빌드 직후 바로 registry로 push.
반응형
'Kubernetes > 일반' 카테고리의 다른 글
| nvidia k8s device driver 및 dcgm 설치 (0) | 2024.05.11 |
|---|---|
| OpenSearch 및 Fluent Bit로 Kubernetes Event 및 Container 로그 저장하기 (0) | 2024.05.06 |
| kr8s - Kubernetes용 Python 클라이언트 라이브러리 (0) | 2023.12.31 |
| kubernetes apiserver 를 통해 Cluster 정보 조회 (1) | 2023.12.25 |
| Strimzi로 Kubernetes에 Apache Kafka 설치 (1) | 2023.12.10 |
Comments