OT-CONTAINER-KIT / redis-operator

A golang based redis operator that will make/oversee Redis standalone/cluster/replication/sentinel mode setup on top of the Kubernetes.
https://ot-redis-operator.netlify.app/
Apache License 2.0
742 stars 207 forks source link

Specify the port number of the NodePort of Redis #762

Open mkadokawa-idcf opened 5 months ago

mkadokawa-idcf commented 5 months ago

Is your feature request related to a problem? Please describe.

Currently, it is not possible to specify the port number of the Redis NodePort. With the default settings, a port number between 30000 and 32767 is randomly assigned.

Describe the solution you'd like

I want to specify the port number of the NodePort as follows.

---
apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: Redis
metadata:
  name: redis-standalone
spec:
  kubernetesConfig:
    image: quay.io/opstree/redis:v7.0.12
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 101m
        memory: 128Mi
      limits:
        cpu: 101m
        memory: 128Mi
    service:
      serviceType: NodePort
      nodePort: 31111   # specify the NodePort number here

Describe alternatives you've considered

https://github.com/OT-CONTAINER-KIT/redis-operator/blob/master/k8sutils/services.go#L49-L54 I would like to make the following changes to the above section.

func generateServiceDef(serviceMeta metav1.ObjectMeta, epp exporterPortProvider, ownerDef metav1.OwnerReference, headless bool, serviceType string, port, nodePort int, extra ...corev1.ServicePort) *corev1.Service {
    ....
    service := &corev1.Service{
        TypeMeta:   generateMetaInformation("Service", "v1"),
        ObjectMeta: serviceMeta,
        Spec: corev1.ServiceSpec{
            Type:      generateServiceType(serviceType),
            ClusterIP: "",
            Selector:  serviceMeta.GetLabels(),
            Ports: []corev1.ServicePort{
                {
                    Name:       PortName,
                    Port:       int32(port),
                    TargetPort: intstr.FromInt(int(port)),
                                        NodePort:   int32(nodePort)   # add here
                    Protocol:   corev1.ProtocolTCP,
                },
            },
        },
    }
        ....

What version of redis-operator are you using?

redis-operator version: v0.15.1

Additional context

The following comments are similar in intent to this issue. https://github.com/OT-CONTAINER-KIT/redis-operator/issues/79#issuecomment-848669389

drivebyer commented 5 months ago

If the NodePort is allocated directly on the node, the service creation will fail. In my opinion, we should allow Kubernetes to handle the allocation of NodePort.