1. Using kubernetes gateway.networking.k8s.io with rabbitmq.com

    TypeScript

    To use Kubernetes Gateway API with RabbitMQ, you'd typically set up an Ingress-like resource that is part of the Gateway API (gateway.networking.k8s.io) to manage external access to the services in your Kubernetes cluster, like RabbitMQ. Gateway is a new Kubernetes resource that aims to provide more powerful traffic routing and management capabilities than the traditional Ingress.

    The Gateway resource allows you to define how traffic is handled at the edge of your cluster and can be paired with Route resources to define more complex traffic routing. For RabbitMQ, which is often deployed as a StatefulSet in Kubernetes, you'd use a Gateway to declare how external traffic should be allowed to reach your RabbitMQ services.

    Below is a Pulumi program written in TypeScript that demonstrates how to set up a simple Gateway and HTTPRoute resources in Kubernetes to route external traffic to a RabbitMQ service. The RabbitMQ instance itself is not within the scope of this program; it is assumed that you have RabbitMQ running in your cluster, perhaps via the RabbitMQ Operator or a Helm chart.

    import * as k8s from "@pulumi/kubernetes"; // Create a GatewayClass, a resource that provides a template for Gateways. const gatewayClass = new k8s.networking.v1alpha1.GatewayClass("rabbitmq-gateway-class", { metadata: { name: "rabbitmq-gateway-class", }, spec: { controller: "example.com/gateway-controller", }, }); // Create a Gateway, a resource that manages incoming and outgoing traffic in your Kubernetes cluster. const gateway = new kubernetes.networking.v1alpha1.Gateway("rabbitmq-gateway", { metadata: { name: "rabbitmq-gateway", }, spec: { gatewayClassName: "rabbitmq-gateway-class", listeners: [ { protocol: "HTTP", port: 80, routes: { kind: "HTTPRoute", selector: { matchLabels: { app: "rabbitmq", }, }, namespaces: { from: "All", }, }, }, ], }, }); // Replace 'your-rabbitmq-service-name' with the actual name of your RabbitMQ service // and 'your-namespace' with the namespace where your RabbitMQ service is deployed. const rabbitmqRoute = new k8s.networking.v1alpha1.HTTPRoute("rabbitmq-http-route", { metadata: { name: "rabbitmq-http-route", labels: { app: "rabbitmq", }, }, spec: { gateways: { allow: "All", }, hostnames: ["rabbitmq.example.com"], rules: [ { matches: [ { path: { type: "Prefix", value: "/", }, }, ], forwardTo: [ { service: "your-rabbitmq-service-name", port: 5672, weight: 1, }, ], }, ], }, }); // Export the URL of the RabbitMQ Gateway export const rabbitMqUrl = `http://${gateway.metadata.name}.example.com`;

    In this program, the GatewayClass defines the controller responsible for managing the Gateway resources. The Gateway resource specifies the listeners where you configure the routing rules. This Gateway listens on port 80 for HTTP traffic.

    The HTTPRoute resource, named rabbitmq-http-route, specifies the traffic routing rules. The labels selector matches the labels of the RabbitMQ service to which you want to forward traffic. In the hostnames field, replace rabbitmq.example.com with the desired DNS hostname that should route to the RabbitMQ service. The forwardTo field defines the target service and port. Replace your-rabbitmq-service-name with the actual service name of your RabbitMQ service, and make sure that the port matches the one your RabbitMQ service is listening on, which by default is 5672 for RabbitMQ.

    Please ensure you have the Gateway API resources defined in your Kubernetes cluster. The Gateway API is an evolving project, and support for it might have to be specifically enabled in your cluster. Check the version of your Kubernetes cluster and ensure the Gateway API is available and enabled before applying this Pulumi program.

    Remember to replace placeholders like your-rabbitmq-service-name, your-namespace, and rabbitmq.example.com with actual values that correspond to your environment setup.