[Home-K8S] #22 FluxCD 계층과 분리 / 다중 클러스터 리소스 공유와 설정 분리
FluxCD - yaml 앞서 fluxcd 를 이용해서 helm chart 를 구성했습니다. 그 외에 일반적인 yaml
언제 어디서나 어떤 디바이스로도 개발을 진행하고 싶을 때, 웹으로 개발환경을 구성하고 싶었습니다. 그리고 code-server가 있다는 것을 알았죠.
code-server는 웹에서 브라우저를 이용해서 사용할 수 있는 VSCode 입니다. VSCode의 거의 모든 기능을 지원하지만, 확장 프로그램에서 가끔 지원하지 않는 게 있습니다.
(물론 extension을 파일로 다운받아서 code-server에서 적용하면 되긴 합니다.)
code-server를 이용하는 이유 중에 하나는 터미널이 있는 것입니다. k8s도 관리를 해야 하기 때문에 기본적으로 터미널을 편하게 쓸 수 있게 하는 게 좋아요.
code-server에서 사용할 kubeconfig를 지금 k8s를 사용하는 kubeconfig에서 가져옵니다. 그래야 kubectl을 사용할 수 있겠죠?
kubectl create secret generic kubeconfig \
--from-file=/home/user/.kube/config \
-n code-serverkubeconfig to k8s Secret
Code-server Docker Image: https://hub.docker.com/r/codercom/code-server
아무래도 code-server는 설정할 config가 별로 없어서 작성하기는 편합니다.
그냥 code-server 이미지를 이용해서 구축을 하면 되지만, 우리는 kubectl을 사용해야 하니까, kubectl과 helm을 적용하고 kubeconfig까지 적용하는 것으로 진행합니다.
initcontainer로 kubectl, helm을 가지고 와서 code-server의 경로에 저장해 줍니다.
이런 식이면 다른 패키지도 쉽게 적용할 수 있게죠?
apiVersion: v1
kind: ConfigMap
metadata:
name: code-server-config
namespace: code-server
data:
config.yaml: |
bind-addr: 127.0.0.1:8080
auth: none
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: code-server
name: code-server
namespace: code-server
spec:
replicas: 1
selector:
matchLabels:
app: code-server
template:
metadata:
labels:
app: code-server
spec:
initContainers: # kubectl,helm 설치
- name: kubectl-copy
image: bitnami/kubectl
command: ["cp","/opt/bitnami/kubectl/bin/kubectl","/mnt/bin/kubectl"]
volumeMounts:
- name: bin-volume
mountPath: /mnt/bin
- name: helm-copy
image: alpine/helm
command: ["cp","/usr/bin/helm","/mnt/bin/helm"]
volumeMounts:
- name: bin-volume
mountPath: /mnt/bin
containers:
- image: codercom/code-server:latest
name: code-server
ports:
- containerPort: 8080
env:
- name: KUBECONFIG
value: /home/coder/.kube/config
volumeMounts:
- name: bin-volume
mountPath: /usr/local/bin/kubectl
subPath: kubectl
- name: bin-volume
mountPath: /usr/local/bin/helm
subPath: helm
- name: kubeconfig
mountPath: /home/coder/.kube
readOnly: true
- name: code-config
mountPath: /home/coder/.config/code-server
volumes:
- name: bin-volume
emptyDir: {}
- name: kubeconfig
secret:
secretname: kubeconfig
- name: code-config
configMap:
name: code-server-configkubeconfig와 kubectl까지 구성했으니까 이제 외부인이 여기 접속하게 되면 모든 것이 털리게 됩니다. 그래서 기본적인 인증 서비스를 달아줍니다. 물론 기본적으로 제공되는 것이 있습니다.
apiVersion: v1
kind: ConfigMap
metadata:
name: code-server-config
namespace: code-server
data:
config.yaml: |
bind-addr: 127.0.0.1:8080
auth: password
password: password1234
kubectl create secret generic basic-auth \
--from-file=./auth \
-n code-serverapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: basic-authapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: code-server
namespace: code-server
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/auth-url: "http://authelia.authelia.svc.cluster.local:9091/api/verify"
nginx.ingress.kubernetes.io/auth-response-headers: "Remote-User, Remote-Name, Remote-Email, Remote-Groups"
nginx.ingress.kubernetes.io/auth-signin: "https://authelia.dogring.kr/"
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:원래는 무료 도메인을 사용하고 각 서비스 별로 path만 다르게 해서 사용하려고 했습니다. 근데 최근 code-server가 base-path config를 제공하지 않아요. 그래서 어쩔 수 없이 도메인을 구매할 수 밖에 없었어요.
base-path를 제공하지 않으니까 path로 처음에 code-server에 연결을 해도 /path를 빼고 리디렉션을 해서 정상적으로 작동하지 않습니다.
확실히 code-server를 이용해서 브라우저만 있으면 어디서든 제 환경에 접속이 가능하니까 편하더라구요.
태블릿과 키보드만 들고 다니면서 작업하기도 하고, pod의 log를 볼 때도 터미널 틀어놓고 과정을 보기도 하고, 잘 쓰고 있어요.
다음에는 code-server에서 python을 위한 Jupyter 서버 구성 방법을 작성하겠습니다.
Comments