redhat-developer / vscode-openshift-tools

OpenShift extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=redhat.vscode-openshift-connector
MIT License
93 stars 60 forks source link

Context menu to expose a `Deployment` as a `Route` or `Ingress`. #3072

Open datho7561 opened 1 year ago

datho7561 commented 1 year ago

It would be nice to expose a running service to the internet using a Route (in the case of OpenShift) or Ingress (in the case of other Kubernetes distributions).

Here's how to create a Route in OpenShift, given that $NAME_OF_DEPLOYMENT is a deployment that's in the current name:

oc expose deployment $NAME_OF_DEPLOYMENT

Here's an example of an Ingress yaml in Kubernetes:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wildwest-backend-ingress
spec:
  defaultBackend:
    service:
      name: wildwest-backend-app
      port:
        number: 8080

The values we will have to change depending on the deployment are:

In order to create the ingress, you will need to run oc apply -f ingress-definition.yaml.

A few final thoughts:

  1. It might also be possible to include the route or ingress in the devfile by embedding the YAML using the additional Kubernetes resources feature. For instance, this is how odo creates ServiceBindings:

    // ...
    components:
    - kubernetes:
    inlined: |
      apiVersion: binding.operators.coreos.com/v1alpha1
      kind: ServiceBinding
      metadata:
        creationTimestamp: null
        name: my-binding
      spec:
        application:
          group: apps
          kind: Deployment
          name: using-go-app
          version: v1
        bindAsFiles: true
        detectBindingResources: true
        services:
        - group: postgres-operator.crunchydata.com
          id: my-binding
          kind: PostgresCluster
          name: example-postgres
          namespace: default
          resource: postgresclusters
          version: v1beta1
      status:
        secret: ""
    name: my-binding
    // ...

    The benefit of this approach is that, if I understand correctly, odo will manage the lifecycle of this Kubernetes object by creating it when dev is started and deleting it when dev is stopped

  2. A final aspect of this change is that we should alert the user that this will expose the service to the public if the cluster is capable of exposing services to the public, and require an additional confirmation in order to do this. We shouldn't try to detect if the cluster is capable of exposing public endpoints, since that is really difficult. Instead we should always show this warning.

  3. Not all Kubernetes clusters are capable of creating an ingress. They require an ingress controller. On minikube the ingress controller that is automatically set up is the nginx one. Maybe we should hide the UI option if the cluster is not OpenShift and doesn't have an ingress controller set up?

datho7561 commented 1 year ago

I have a POC of the Route portion of this working

datho7561 commented 1 year ago

I ran into some issues while trying to get similar functionality for Ingresses to work:

datho7561 commented 1 year ago

I messed up, we don't actually need this to get the Wild West demo application working.

datho7561 commented 1 year ago

Why I've changed my mind and think this isn't a good idea

datho7561 commented 10 months ago

I've changed my mind again: I think we should support Routes but not Ingress:

datho7561 commented 8 months ago

@vrubezhny You mentioned wanting more issues to work on. What do you think of this issue?

We only need to make it work for OpenShift clusters, so we can use Routes