728x90
반응형
Overview
1주차 도전 과제는 `Deploying Cassandra with a StatefulSet` 과 `kui 설치` 를 진행해 보았다.
Cassandra란?
Apache Cassandra는 많은 상용 서버에서 매우 많은 양의 구조화된 데이터를 관리하도록 설계된 무료 오픈 소스 분산 NoSQL 데이터베이스 시스템으로, 단일 장애 지점 없이 고가용성을 제공한다.
Deploying Cassandra with a StatefulSet
Kubernetes에서 Apache Cassandra를 배포해보려고 한다. 데이터베이스인 Cassandra는 데이터 내구성을 제공하기 위해 영구 스토리지가 필요하다. 그리고 Cassandra seed provider를 사용하면 데이터베이스가 Cassandra 클러스터에 조인할 때 새 Cassandra 인스턴스를 검색할 수 있다.
Cassandra용 헤드리스 서비스 만들기
# cassandra-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: cassandra
name: cassandra
spec:
clusterIP: None
ports:
- port: 9042
selector:
app: cassandra
# cassandra-service.yaml 배포
kubectl apply -f https://k8s.io/examples/application/cassandra/cassandra-service.yaml
# cassandra-service 확인
k get svc cassandra
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cassandra ClusterIP None <none> 9042/TCP 100s
Statefulset을 사용하여 Cassandra ring 생성
스토리지 클래스만 수정해준다.
# StorageClass 확인
k get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
gp2 (default) kubernetes.io/aws-ebs Delete WaitForFirstConsumer false 23m
gp3 (default) ebs.csi.aws.com Delete WaitForFirstConsumer true 10m
# cassandra-statefulset.yaml
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: cassandra
labels:
app: cassandra
spec:
serviceName: cassandra
replicas: 3
selector:
matchLabels:
app: cassandra
template:
metadata:
labels:
app: cassandra
spec:
terminationGracePeriodSeconds: 1800
containers:
- name: cassandra
image: gcr.io/google-samples/cassandra:v13
imagePullPolicy: Always
ports:
- containerPort: 7000
name: intra-node
- containerPort: 7001
name: tls-intra-node
- containerPort: 7199
name: jmx
- containerPort: 9042
name: cql
resources:
limits:
cpu: "500m"
memory: 1Gi
requests:
cpu: "500m"
memory: 1Gi
securityContext:
capabilities:
add:
- IPC_LOCK
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- nodetool drain
env:
- name: MAX_HEAP_SIZE
value: 512M
- name: HEAP_NEWSIZE
value: 100M
- name: CASSANDRA_SEEDS
value: "cassandra-0.cassandra.default.svc.cluster.local"
- name: CASSANDRA_CLUSTER_NAME
value: "K8Demo"
- name: CASSANDRA_DC
value: "DC1-K8Demo"
- name: CASSANDRA_RACK
value: "Rack1-K8Demo"
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
readinessProbe:
exec:
command:
- /bin/bash
- -c
- /ready-probe.sh
initialDelaySeconds: 15
timeoutSeconds: 5
# These volume mounts are persistent. They are like inline claims,
# but not exactly because the names need to match exactly one of
# the stateful pod volumes.
volumeMounts:
- name: cassandra-data
mountPath: /cassandra_data
# These are converted to volume claims by the controller
# and mounted at the paths mentioned above.
# do not use these in production until ssd GCEPersistentDisk or other ssd pd
volumeClaimTemplates:
- metadata:
name: cassandra-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: gp3
resources:
requests:
storage: 1Gi
EOF
Cassandra Statefulset 검증
k get po,svc,pv,pvc
NAME READY STATUS RESTARTS AGE
pod/cassandra-0 1/1 Running 0 4m14s
pod/cassandra-1 1/1 Running 0 3m11s
pod/cassandra-2 1/1 Running 0 93s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cassandra ClusterIP None <none> 9042/TCP 15m
service/kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 34m
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-5710a239-c95f-4953-8c13-94c006b6a322 1Gi RWO Delete Bound default/cassandra-data-cassandra-2 gp3 90s
persistentvolume/pvc-61a1467d-4bed-4ad3-bac5-f17685891a92 1Gi RWO Delete Bound default/cassandra-data-cassandra-1 gp3 3m7s
persistentvolume/pvc-be749cd9-20cd-4214-b5d6-c10906c30bfd 1Gi RWO Delete Bound default/cassandra-data-cassandra-0 gp3 4m11s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/cassandra-data-cassandra-0 Bound pvc-be749cd9-20cd-4214-b5d6-c10906c30bfd 1Gi RWO gp3 4m14s
persistentvolumeclaim/cassandra-data-cassandra-1 Bound pvc-61a1467d-4bed-4ad3-bac5-f17685891a92 1Gi RWO gp3 3m11s
persistentvolumeclaim/cassandra-data-cassandra-2 Bound pvc-5710a239-c95f-4953-8c13-94c006b6a322 1Gi RWO gp3 93s
Cassandra Statefulset 수정
- replica 3 → 4
kubectl edit statefulset cassandra
...
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: apps/v1
kind: StatefulSet
metadata:
creationTimestamp: 2016-08-13T18:40:58Z
generation: 1
labels:
app: cassandra
name: cassandra
namespace: default
resourceVersion: "323"
uid: 7a219483-6185-11e6-a910-42010a8a0fc0
spec:
replicas: 4
변경사항을 확인한다.
k get sts cassandra
NAME READY AGE
cassandra 4/4 6m22s
Cassandra 삭제
# statefulset 삭제
grace=$(kubectl get pod cassandra-0 -o=jsonpath='{.spec.terminationGracePeriodSeconds}') \
&& kubectl delete statefulset -l app=cassandra \
&& echo "Sleeping ${grace} seconds" 1>&2 \
&& sleep $grace \
&& kubectl delete persistentvolumeclaim -l app=cassandra
# service 삭제
kubectl delete service -l app=cassandra
# 삭제 확인
k get svc,po,pv,pvc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 56m
- 너무 오래 걸린다. 수동으로 전부 지워줘도 된다.
- `k delete pvc cassandra-data-cassandra-0 cassandra-data-cassandra-1...`
Kubectl Kui 설치
curl -LO https://github.com/kubernetes-sigs/kui/releases/download/v13.1.4/Kui-linux-x64.zip
unzip Kui-linux-x64.zip
# 아키텍처 확인
# 환경변수 등록
echo 'export PATH=$PATH:~/Kui-linux-x64' >> ~/.bashrc
source ~/.bashrc
# path 확인
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/.krew/bin:/root/bin:/root/Kui-linux-x64
kubectl kui
/root/Kui-linux-x64/Kui: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory
sudo yum install libatk-bridge-2.0.so.0 atk
# 라이브러리 링크 확인
ldd /root/Kui-linux-x64/Kui | grep not
libcups.so.2 => not found
libgtk-3.so.0 => not found
libpango-1.0.so.0 => not found
libcairo.so.2 => not found
libXcomposite.so.1 => not found
libXdamage.so.1 => not found
libXfixes.so.3 => not found
libXrandr.so.2 => not found
libgbm.so.1 => not found
libxkbcommon.so.0 => not found
libasound.so.2 => not found
sudo yum install cups-libs gtk3 pango cario libXcomposite libXdamage libXfixes libXrandr mesa-libgbm libxkbcommon alsa-lib
kubectl kui
[1019/004012.754239:FATAL:electron_main_delegate.cc(299)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
WSL에서는 안되는거 같습니다. 아쉽네요.
Reference
https://kubernetes.io/docs/tutorials/stateful-application/cassandra/
https://kubernetes.io/docs/tutorials/stateful-application/cassandra/
728x90
반응형
'교육, 커뮤니티 후기 > DOIK (데이터베이스 오퍼레이터 인 쿠버네티스) 스터디' 카테고리의 다른 글
DOIK(Database Operator In Kubernetes) 1주차 (2) | 2023.10.18 |
---|