k8s-in-rpi

created : 2022-05-02T17:11:00+00:00
modified : 2022-05-24T09:03:00+00:00

k8s

TODO (우선순위 순으로)

배경

사양

기본 설명

Kubernetes 설치 -> Kind 설치

Troubleshooting

  Error: failed to create cluster: failed to init node with kubeadm: command "docker exec --privileged <cluster name>-control-plane kubeadm init --skip-phases=pre flight --config=/kind/kubeadm.conf --skip-token-print --v=6

Nginx Ingress 설정

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml
# cluster-issuer.yaml
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-staging
spec:
  acme:
    # The ACME server URL
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    # Email address used for ACME registration
    email: <이메일>
    # Name of a secret used to store the ACME account private key
    privateKeySecretRef:
      name: letsencrypt-staging
    # Enable the HTTP-01 challenge provider
    solvers:
    # An empty 'selector' means that this solver matches all domains
    - selector: {}
      http01:
        ingress:
          class: nginx
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    # The ACME server URL
    server: https://acme-v02.api.letsencrypt.org/directory
    # Email address used for ACME registration
    email: <mail address>
    # Name of a secret used to store the ACME account private key
    privateKeySecretRef:
      name: letsencrypt-prod
    # Enable the HTTP-01 challenge provider
    solvers:
    - http01:
        ingress:
          class: nginx
kubectl apply -f cluster-issuer.yaml

Troubleshooting

Node monitoring tool 설치

# 생략
apiVersion: v1
data:
  grafana.ini: |
    [analytics]
    check_for_updates = true
    [grafana_net]
    url = https://grafana.net
    [log]
    mode = console
    [paths]
    data = /var/lib/grafana/
    logs = /var/log/grafana
    plugins = /var/lib/grafana/plugins
    provisioning = /etc/grafana/provisioning
    [server]
    domain = kube.makerdark98.dev
    root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
    serve_from_sub_path = true
# 생략

Troubleshooting

Jupyter Notebook 설치

# jupyter.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jupyter-fileshare-pv
spec:
  storageClassName: manual
  volumeMode: Filesystem
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /tmp/data/jupyter
    type: Directory
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fileshare-pvc
  labels:
    component: jupyter
spec:
  volumeMode: Filesystem
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  volumeName: jupyter-fileshare-pv
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: base-notebook
  labels:
    app: base-notebook
spec:
  replicas: 1
  selector:
    matchLabels:
      app: base-notebook
  template:
    metadata:
      labels:
        app: base-notebook
    spec:
      containers:
      - name: base-notebook
        image: registry.makerdark98.dev/jupyter/notebook:0.0.1
        ports:
        - containerPort: 8888
        command: ["start-notebook.sh"]
        args: ["--NotebookApp.password='<secret>'", "--NotebookApp.
ip='*'", "--NotebookApp.base_url='/jupyter'"]
        env:
          - name: DOCKER_STACKS_JUPYTER_CMD
            value: nbclassic
          - name: GRANT_SUDO
            value: "yes"
        volumeMounts:
        - name: storage
          mountPath: "/home/jovyan/work"
        securityContext:
          runAsUser: 0
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: fileshare-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: base-notebook-svc
spec:
  type: LoadBalancer
  selector:
    app: base-notebook
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8888
kubectl apply -f jupyter.yaml
# headless-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: headless-svc-base-notebook
  namespace: ingress
spec:
  type: ExternalName
  externalName: base-notebook-svc.jupyter.svc.cluster.local
kubectl apply -f headless-svc.yaml

Troubleshooting

Docker registry, Web UI 띄우기

Troubleshooting


TODO: 실습하기

간단한 Hello World 프로그램 작성하기

docker 이미지로 pod 만들기