自定义路由¶
可以在创建 Pod 时通过 Annotations 来指定需要配置的路由,如下所示:
apiVersion: v1
kind: Pod
metadata:
name: custom-routes
annotations:
ovn.kubernetes.io/routes: |
[{
"dst": "192.168.0.101/24",
"gw": "10.16.0.254"
}, {
"gw": "10.16.0.254"
}]
spec:
containers:
- name: nginx
image: docker.io/library/nginx:alpine
dst
字段为空表示修改默认路由。
如果工作负载为 Deployment、DaemonSet 或 StatefulSet,对应的 Annotation 需要配置在资源的 .spec.template.metadata.annotations
中,示例如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-routes
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
annotations:
ovn.kubernetes.io/routes: |
[{
"dst": "192.168.0.101/24",
"gw": "10.16.0.254"
}, {
"gw": "10.16.0.254"
}]
spec:
containers:
- name: nginx
image: docker.io/library/nginx:alpine
微信群 Slack Twitter Support Meeting