|
| 1 | +# How to enable a Public Endpoint Add-on for OCI Streaming with Apache Kafka |
| 2 | + |
| 3 | +OCI Streaming with Apache Kafka(OSAK), is Oracle Cloud Infrastructure’s managed Kafka service. |
| 4 | +It provides Oracle managed Apache Kafka clusters on OCI and exposes Kafka 100% APIs, so Kafka applications and tools can connect without code rewrites. |
| 5 | +The most recent OSAK update provdes **Public Endpoint**, which can expose your cluster to public network and allow external application to connect to your cluster. |
| 6 | + |
| 7 | +It's easy to add **Public Endpoint** to your cluster with the latest OCI CLI - https://github.com/oracle/oci-cli/releases/tag/v3.86.0 : |
| 8 | + |
| 9 | +### 1. Install and verify OCI CLI verion: |
| 10 | +OCI Cloud Shell and a Linux/Windows host can be used: |
| 11 | + |
| 12 | +``` |
| 13 | +python -m pip install "oci-cli==3.86.0" |
| 14 | +oci --version |
| 15 | +3.86.0 |
| 16 | +``` |
| 17 | + |
| 18 | +### 2. Review Kafka OCI CLI addons help: |
| 19 | +``` |
| 20 | +oci kafka cluster install-public-connectivity-addon |
| 21 | +Usage: oci kafka cluster install-public-connectivity-addon |
| 22 | + [OPTIONS] |
| 23 | +
|
| 24 | +Error: Missing option(s) --name, --authentication-mechanism, --network-cidrs, --kafka-cluster-id. |
| 25 | +``` |
| 26 | + |
| 27 | +### 3. Generate the network-cidrs.json template |
| 28 | +``` |
| 29 | +oci kafka cluster install-public-connectivity-addon --generate-param-json-input network-cidrs > network-cidrs.json |
| 30 | +``` |
| 31 | +IT Generates a sample JSON file for the --network-cidrs parameter. |
| 32 | +The network-cidrs.json file should contain the public IP ranges allowed to access the Kafka public endpoint. |
| 33 | +Example: |
| 34 | +``` |
| 35 | +[ |
| 36 | + "203.0.113.10/32", |
| 37 | + "198.51.100.0/24" |
| 38 | +] |
| 39 | +``` |
| 40 | +### 4. Install the public connectivity add-on |
| 41 | +``` |
| 42 | +oci kafka cluster install-public-connectivity-addon \ |
| 43 | + --kafka-cluster-id <cluster-ocid> \ |
| 44 | + --name <endpoint-name> \ |
| 45 | + --authentication-mechanism SASL \ |
| 46 | + --network-cidrs file://network-cidrs.json \ |
| 47 | + --wait-for-state SUCCEEDED |
| 48 | +``` |
| 49 | +Parameter Explanation: |
| 50 | +> --kafka-cluster-id The OCID of the OSAK Kafka cluster.<br> |
| 51 | +> --name The name of the public connectivity add-on.<br> |
| 52 | +> --authentication-mechanism SASL Enables SASL-based authentication for the public endpoint add-on.(SASL or MTLS) <br> |
| 53 | +> --network-cidrs file://network-cidrs.json Loads the allowed CIDR list from the local JSON file, generated in 3.<br> |
| 54 | +> --wait-for-state SUCCEEDED Waits until the OCI work request completes successfully.<br> |
| 55 | +
|
| 56 | + |
| 57 | +### 5. List installed add-ons for the Kafka cluster |
| 58 | +``` |
| 59 | +oci kafka cluster list-addons \ |
| 60 | + --kafka-cluster-id <cluster-ocid> \ |
| 61 | + --all |
| 62 | +``` |
| 63 | + |
| 64 | +### 6. Get details for the public endpoint add-on |
| 65 | +``` |
| 66 | +oci kafka cluster get-addon \ |
| 67 | + --kafka-cluster-id <cluster-ocid> \ |
| 68 | + --addon-name <endpoint-name> |
| 69 | +``` |
| 70 | +The expected output: |
| 71 | +``` |
| 72 | +{ |
| 73 | + "data": { |
| 74 | + "addon-type": "PUBLICCONNECTIVITY", |
| 75 | + "authentication-mechanism": "SASL", |
| 76 | + "bootstrap-url": "bootstrap.....com:xxxx", |
| 77 | + "description": null, |
| 78 | + "lifecycle-state": "ACTIVE", |
| 79 | + "name": "SylwekPE", |
| 80 | + "network-cidrs": [ |
| 81 | + "0.0.0.0/0" |
| 82 | + ], |
| 83 | + "time-created": "2026-06-11T10:40:50.694000+00:00", |
| 84 | + "time-updated": "2026-06-11T11:08:39.870000+00:00" |
| 85 | + }, |
| 86 | + "etag": "1e0c068328174268e1d2ac758c2338e71e7e8236a92da4fc9758cb9bcce176df--gzip" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Now you can connect to your cluster using provided bootstrap-url from any location (or restriced to CIDRs ranges): |
| 91 | + |
| 92 | +``` |
| 93 | +import getpass |
| 94 | +import os |
| 95 | +import ssl |
| 96 | +import sys |
| 97 | +
|
| 98 | +from kafka import KafkaAdminClient |
| 99 | +
|
| 100 | +
|
| 101 | +CLUSTER = "my.bootstrap_url.com:port" |
| 102 | +USERNAME = os.getenv("KAFKA_SASL_USERNAME", "mykafka_username") |
| 103 | +PASSWORD = os.getenv("KAFKA_SASL_PASSWORD") or getpass.getpass("Kafka password: ") |
| 104 | +
|
| 105 | +
|
| 106 | +try: |
| 107 | + admin = KafkaAdminClient( |
| 108 | + bootstrap_servers=CLUSTER, |
| 109 | + security_protocol="SASL_SSL", |
| 110 | + sasl_mechanism="SCRAM-SHA-512", |
| 111 | + sasl_plain_username=USERNAME, |
| 112 | + sasl_plain_password=PASSWORD, |
| 113 | + ssl_context=ssl._create_unverified_context(), |
| 114 | + request_timeout_ms=10000, |
| 115 | + api_version_auto_timeout_ms=10000, |
| 116 | + ) |
| 117 | + topics = sorted(admin.list_topics()) |
| 118 | + print(f"connected: {len(topics)} topics visible") |
| 119 | + for topic in topics: |
| 120 | + print(topic) |
| 121 | + admin.close() |
| 122 | +except Exception as exc: |
| 123 | + print(f"failed: {type(exc).__name__}: {exc}") |
| 124 | + sys.exit(1) |
| 125 | +``` |
| 126 | +and the response: |
| 127 | +``` |
| 128 | +connected: 23 topics visible |
| 129 | +AMER_CUSTOMERS |
| 130 | +AMER_CUSTOMERS_INFO |
| 131 | +AMER_NEXT_CUST |
| 132 | +AMER_NEXT_ORDER |
| 133 | +AMER_ORDERS |
| 134 | +AMER_ORDERS_PRODUCTS |
| 135 | +AMER_ORDERS_STATUS_HISTORY |
| 136 | +AMER_PRODUCTS |
| 137 | +..... |
| 138 | +``` |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
0 commit comments