Search code examples
google-kubernetes-engineopen-policy-agent

How to find the OPA url after deploying opa as a side car on GKE


I have deployed OPA as a side car with my application.Now I want to find out the OPA url because I want to put it as an endpoint. OPA documentation has mentioned that we can find out the OPA url after deploying, using "OPA_URL=$(minikube service opa --url)" and then this command "curl $OPA_URL/v1/data". So I want to know about how can I do the same thing with GKE ?


Solution

  • By default, OPA binds on 0.0.0.0:8181 so you would be able to reach it at POD_IP:8181. You can control this by setting --addr.

    For example, if you only want to expose the OPA API inside the pod (which makes sense when you're running it as a sidecar), you can do the following:

    opa run --server --addr localhost:8181 --diagnostic-addr 0.0.0.0:8182
    

    This will:

    • Start opa as a server (opa run --server)
    • Bind the OPA API on localhost only
    • Bind the diagnostic API on all interfaces (e.g., so that health checks from the kubelet can be configured)

    If you want to expose OPA as a service outside the pod (in which case, it's not really used as sidecar anymore) you would have to create a Kubernetes Service object like you would for any other workload.