dragonflydb / dragonfly-operator

A Kubernetes operator to install and manage Dragonfly instances.

Home Page:https://www.dragonflydb.io/docs/managing-dragonfly/operator/installation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to specify a namespace via Dragonfly CRD during installation

qianjunakasumi opened this issue · comments

Hello, I'm using dragonfly-operator to deploy my instance,
I would like to be able to specify its installation namespace, this sample yaml installed dragonfly in the default namespace.
because little experience with kubernetes and checked some documentation or search by google but couldn't find a solution, I hope to get some help

my yaml:

apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
  labels:
    app.kubernetes.io/name: dragonfly
    app.kubernetes.io/instance: dragonfly-instance
    app.kubernetes.io/part-of: dragonfly-operator
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/created-by: dragonfly-operator
  name: dragonfly-instance
spec:
  replicas: 2
  resources:
    requests:
      cpu: 500m
      memory: 500Mi
    limits:
      cpu: 600m
      memory: 750Mi

kubectl get pods -n default

NAME                                      READY   STATUS    RESTARTS       AGE
dragonfly-instance-0                      2/2     Running   0              30m
dragonfly-instance-1                      2/2     Running   0              22m

set app.kubernetes.io/namespace: <my-namespace> but cannot works, set namespace field in spec which is invalid value.
If need more information I appreciate to share

Hi @qianjunakasumi, first make sure the namespace exists in your cluster by running kubectl get ns. If not, create one by running kubectl create namespace <your-namespace>.

Once the namespace is created, either specify namespace under metadata in the yaml or use -n flag in kubectl apply command to specify the namespace.

Corrected yaml

apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
  labels:
    app.kubernetes.io/name: dragonfly
    app.kubernetes.io/instance: dragonfly-instance
    app.kubernetes.io/part-of: dragonfly-operator
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/created-by: dragonfly-operator
  name: dragonfly-instance
  namespace: <your-namespace>
spec:
  replicas: 2
  resources:
    requests:
      cpu: 500m
      memory: 500Mi
    limits:
      cpu: 600m
      memory: 750Mi

Or via command-line:

kubectl apply -f <your-yaml-file> -n <your-namespace>

Hope this helps :)

Thanks for your help @Abhra303 , it's working fine for me.
Do you consider we may add namespace description to the documentation to help others?

best regards

Actually, this is not a dragonfly-specific configuration to specify a namespace. It works for any namespaced resources (e.g. Pod, Deployment, Statefulset, etc.). So not sure whether we should add it to documentation. Wdyt @ashotland ?

Yeah the object metadata is part of all resources by default, and I don't think this is necessary to have more documentation about it. Closing this issue hence.