配置BCI Pod访问集群内Service
更新时间:2025-02-26
概述
BCI支持从BCI实例中访问K8S ClusterIP类型Service。如果您需要在BCI实例中访问集群中ClusterIP, 您需要在Pod Spec Yaml中添加如下Annotation,用于开启功能:
bci.virtual-kubelet.io/kube-proxy-enabled: true
Annotation 请添加在Pod的metadata下,例如:创建Deployment时,Annotation需添加在spec>template>metadata下。 仅支持在创建BCI Pod时添加BCI相关Annotation来生效BCI功能,已成功的BCI Pod只能重建来生效。
配置示例
以创建一个简单的Nginx为例,Nginx的Pod 会调度到VNode上:
                Plain Text
                
            
            1kind: Service
2apiVersion: v1
3metadata:
4  name: nginx-service
5spec:
6  selector:
7    app: nginx
8  ports:
9  - name: nginx-port
10    port: 80
11    targetPort: 80
12    protocol: TCP
13---
14apiVersion: v1
15kind: Pod
16metadata:
17  name: nginx-bci
18  labels:
19    app: nginx
20  annotations:
21    "bci.virtual-kubelet.io/kube-proxy-enabled": "true" #添加这个annotation
22spec:
23  nodeSelector:
24    type: "virtual-kubelet"
25  tolerations:
26  - key: "virtual-kubelet.io/provider"
27    operator: "Equal"
28    value: "baidu"
29    effect: "NoSchedule"
30  containers:
31  - name: sun-nginx-host
32    imagePullPolicy: IfNotPresent
33    image: hub.baidubce.com/jpaas-public/nginx-alpine-go:latest
34    resources:
35      limits:
36        cpu: 0.5
37        memory: 1Gi
38      requests:
39        cpu: 0.5
40        memory: 1Gi
            