我有一个带有以下 yaml 的 Strimzi 集群设置。
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
name: kafka
spec:
kafka:
replicas: 3
listeners:
- name: plain
port: 9092
type: internal
tls: false
- name: tls
port: 9093
type: internal
tls: true
authentication:
type: tls
- name: external
port: 9094
type: route
authentication:
type: scram-sha-512
tls: true
豆荚很好,我KafkaUser
用 SCRAM-512 创建了一个 CR,如下所示 -
apiVersion: kafka.strimzi.io/v1beta1
kind: KafkaUser
metadata:
name: scram-user
labels:
strimzi.io/cluster: kafka
spec:
authentication:
type: scram-sha-512
我已经从密钥中正确提取了 SCRAM 密码,并ca.crt
从 cluster-ca-cert 密钥中获取了文件。我正在尝试遵循此示例中的 Go Sarama 代码 - https://github.com/Shopify/sarama/blob/master/examples/sasl_scram_client/main.go
我还从 OpenShift Route 正确获取了引导服务器地址,但我似乎无法连接。
go run sarama.go scram_client.go -brokers bootstrap-address:443 -username scram-user -passwd esoy2WksWRBp -topic test-topic -algorithm sha512 -tls true -ca /path/ca.crt
我已经尝试了上述命令的一些变体,添加-certificate
或-key
标志,但似乎没有一个工作。我的监听器设置错误吗?
编辑 - 忘记包含并提及它,但这是我从 Go Sarama 代码中得到的错误。
[Sarama] 2021/08/18 09:22:36 Failed to send SASL handshake kafka-broker:443: x509: certificate signed by unknown authority
[Sarama] 2021/08/18 09:22:36 Closed connection to broker kafka-broker:443
[Sarama] 2021/08/18 09:22:36 client/metadata got error from broker -1 while fetching metadata: x509: certificate signed by unknown authority
[Sarama] 2021/08/18 09:22:36 client/metadata no available broker to send metadata request to
[Sarama] 2021/08/18 09:22:36 client/brokers resurrecting 1 dead seed brokers
[Sarama] 2021/08/18 09:22:36 Closing Client
[Producer] 2021/08/18 09:22:36 failed to create producer: kafka: client has run out of available brokers to talk to (Is your cluster reachable?)
exit status 1
所以它看起来是一个证书问题,但我似乎已经按照正确的说明来获取证书。我的 Kafka 代理刚刚命名为 kafka,因此秘密命名为 kafka-cluster-ca-cert。该ca.crt
文件是我提供给 Sarama 代码的路径。
oc get secret kafka-cluster-ca-cert -o jsonpath='{.data.ca\.crt}' | base64 -d > ca.crt
如果重要,请描述秘密 -
╰─ oc describe secret kafka-cluster-ca-cert
Name: kafka-cluster-ca-cert
Namespace: strimzi
Labels: app.kubernetes.io/instance=kafka
app.kubernetes.io/managed-by=strimzi-cluster-operator
app.kubernetes.io/name=strimzi
app.kubernetes.io/part-of=strimzi-kafka
strimzi.io/cluster=kafka
strimzi.io/kind=Kafka
strimzi.io/name=strimzi
Annotations: strimzi.io/ca-cert-generation: 0
Type: Opaque
Data
====
ca.crt: 1854 bytes
ca.p12: 1687 bytes
ca.password: 12 bytes