企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] >[info] 本节文章不解释字段的含义,先体验traefik代理http服务给k8s集群外部访问。 `kubernetes` 集群创建 `whoami` 应用。然后通过 `kubernetesCRD` 服务发现机制,通过 `traefik` 把业务暴露出去。 ## 创建 whoami 应用 ```shell cat <<- 'EOF' | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: whoami labels: name: whoami spec: replicas: 1 selector: matchLabels: app: whoami template: metadata: labels: app: whoami spec: containers: - name: whoami image: traefik/whoami ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: whoami spec: ports: - name: http port: 80 selector: app: whoami EOF ``` 查看创建资源情况 ```shell kubectl get pod -l app=whoami kubectl get svc whoami ``` ![](https://img.kancloud.cn/6a/14/6a1493e14dc1196d1371c9bab245a5da_846x178.png) ## 创建 IngressRoute 资源 ```shell cat <<- 'EOF' | kubectl apply -f - --- apiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: name: whoami spec: entryPoints: - web routes: - match: Host(`whoami.ecloud.com`) kind: Rule services: - name: whoami port: 80 EOF ``` 查看创建资源情况 ```shell kubectl describe ingressroute.traefik.io whoami kubectl get ingressroute.traefik.io whoami ``` ![](https://img.kancloud.cn/b1/37/b13755ad0168243ade001be0cfde7fa0_1191x643.png) ## 验证通过 traefik 测试是否可访问应用 命令行验证: `curl -H "Host: whoami.ecloud.com" http://192.168.32.100` ![](https://img.kancloud.cn/6b/02/6b024161c19231bb0d24ea0986481274_1053x383.png)