Ssup2 Blog logo Ssup2 Blog

Operator SDK User Guide에 소개된 Nginx Operator 예제를 통해 Operator SDK와 Helm Operator를 분석한다.

1. Operator SDK, Helm Operator

1.1. Helm Operator Component

1.2. Helm Operator HA

2. Nginx Helm Operator

2.1. 개발 환경

개발 환경은 다음과 같다.

2.2. Operator SDK 설치

# mkdir -p ~/operator-sdk
# cd ~/operator-sdk
# RELEASE_VERSION=v0.8.0
# curl -OJL https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu
# chmod +x operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu && sudo cp operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu /usr/local/bin/operator-sdk && rm operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu
# operator-sdk
An SDK for building operators with ease

Usage:
  operator-sdk [command]
...
[Shell 1] Operator SDK 설치

Kubernetes Operator SDK CLI를 설치하고 동작을 확인한다.

2.3. Project 생성

# operator-sdk new example-k8s-operator-helm --api-version=example.com/v1alpha1 --kind=Nginx --type=helm
# cd example-k8s-operator-helm && ls
build  deploy  helm-charts  watches.yaml
[Shell 2] Project 생성

2.4. Nginx CRD 생성

# kubectl create -f deploy/crds/example_v1alpha1_nginx_crd.yaml
[Shell 3] Nginx CRD 생성

2.5. Nginx Operator 구동

# operator-sdk build supsup5642/nginx-operator:v0.0.1
# sed -i 's|REPLACE_IMAGE|supsup5642/nginx-operator:v0.0.1|g' deploy/operator.yaml
# docker push supsup5642/nginx-operator:v0.0.1
[Shell 4] Nginx Operator Image 생성 및 Push
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: null
  name: example-k8s-operator-nginx
rules:
- apiGroups:
  - ""
  resources:
  - namespaces
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - pods
  - services
  - configmaps
  - secrets
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - deployments
  verbs:
  - '*'
- apiGroups:
  - example.com
  resources:
  - '*'
  verbs:
  - '*'
[파일 1] deploy/role.yaml
# kubectl create -f deploy/service_account.yaml
# kubectl create -f deploy/role.yaml
# kubectl create -f deploy/role_binding.yaml
# kubectl create -f deploy/operator.yaml
[Shell 5] Nginx Operator 구동

2.6. Nginx CR 생성을 통한 Nginx 구동

# kubectl apply -f deploy/crds/example_v1alpha1_nginx_cr.yaml
[Shell 6] Nginx 구동
# kubectl get pod
NAME                                                       READY   STATUS    RESTARTS   AGE
example-k8s-operator-helm-66496b4665-zhdzq                 1/1     Running   0          16m
example-nginx-2o18v8fiksct1fk0lol9r6yv7-5cc9b7f59f-qh87x   1/1     Running   0          16m
[Shell 7] Nginx 구동 확인

3. 참조