k8s部署kafka并web访问
时间: 2023-07-29 15:13:40 浏览: 258
kafka介绍及部署
4星 · 用户满意度95%
要在Kubernetes上部署Kafka并通过Web界面访问,可以遵循以下步骤:
1. 创建一个Kafka集群的YAML文件,定义Kafka集群的服务和部署对象。如下所示:
```
apiVersion: v1
kind: Service
metadata:
name: kafka
labels:
app: kafka
spec:
ports:
- name: kafka
port: 9092
protocol: TCP
targetPort: 9092
- name: jmx
port: 7203
protocol: TCP
targetPort: 7203
selector:
app: kafka
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka
spec:
replicas: 3
selector:
matchLabels:
app: kafka
template:
metadata:
labels:
app: kafka
spec:
containers:
- name: kafka
image: wurstmeister/kafka:2.13-2.7.0
ports:
- containerPort: 9092
- containerPort: 7203
env:
- name: KAFKA_ADVERTISED_HOST_NAME
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KAFKA_CREATE_TOPICS
value: "test:2:3"
- name: KAFKA_ZOOKEEPER_CONNECT
value: "zookeeper:2181"
```
上述YAML文件中,定义了一个Kafka集群的服务和部署对象,使用了wurstmeister/kafka的镜像,同时配置了Kafka的参数,包括`KAFKA_ADVERTISED_HOST_NAME`、`KAFKA_CREATE_TOPICS`和`KAFKA_ZOOKEEPER_CONNECT`等。
2. 创建一个Kafka Manager的YAML文件,定义Kafka Manager的服务和部署对象。如下所示:
```
apiVersion: v1
kind: Service
metadata:
name: kafka-manager
labels:
app: kafka-manager
spec:
ports:
- name: http
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: kafka-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-manager
spec:
replicas: 1
selector:
matchLabels:
app: kafka-manager
template:
metadata:
labels:
app: kafka-manager
spec:
containers:
- name: kafka-manager
image: hlebalbau/kafka-manager:latest
ports:
- containerPort: 9000
env:
- name: ZK_HOSTS
value: "zookeeper:2181"
```
上述YAML文件中,定义了一个Kafka Manager的服务和部署对象,使用了hlebalbau/kafka-manager的镜像,同时配置了Zookeeper的地址和端口。
3. 在Kubernetes上部署Kafka集群和Kafka Manager。使用`kubectl apply -f`命令部署上述两个YAML文件。
4. 访问Kafka Manager的Web界面。使用`kubectl get service`命令查看Kafka Manager的服务IP地址和端口,然后在浏览器中输入`http://<kafka-manager-ip>:<kafka-manager-port>`来访问Kafka Manager的Web界面。在Kafka Manager的Web界面中,可以查看Kafka集群的状态、管理topic、查看消费者组等。
阅读全文