[root@k8s-master configmap]# ls demoapp-conf.d/ #3个配置文件
envoy.yaml lds.conf myserver.conf
[root@k8s-master configmap]# cat demoapp-conf.d/envoy.yaml
node:
id: sidecar-proxy
cluster: demoapp-cluster
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
dynamic_resources:
lds_config:
path: /etc/envoy/lds.conf
static_resources:
clusters:
– name: local_service
connect_timeout: 0.25s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: local_service
endpoints:
– lb_endpoints:
– endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 8080
[root@k8s-master configmap]# cat demoapp-conf.d/lds.conf
{
“version_info”: “0”,
“resources”: [
{
“@type”: “type.googleapis.com/envoy.api.v2.Listener”,
“name”: “listener_0”,
“address”: {
“socket_address”: {
“address”: “0.0.0.0”,
“port_value”: 80
}
},
“filter_chains”: [
{
“filters”: [
{
“name”: “envoy.http_connection_manager”,
“config”: {
“stat_prefix”: “ingress_http”,
“codec_type”: “AUTO”,
“route_config”: {
“name”: “local_route”,
“virtual_hosts”: [
{
“name”: “local_service”,
“domains”: [
“*”
],
“routes”: [
{
“match”: {
“prefix”: “/”
},
“route”: {
“cluster”: “local_service”
}
}
]
}
]
},
“http_filters”: [
{
“name”: “envoy.router”
}
]
}
}
]
}
]
}
]
}
[root@k8s-master configmap]# cat configmaps-volume-demo2.yaml
apiVersion: v1
kind: Pod
metadata:
name: configmaps-volume-demo2
namespace: default
spec:
containers:
– name: proxy
image: envoyproxy/envoy-alpine:v1.14.1
command: [/bin/sh,-c,envoy -c /etc/envoy/..data/envoy.yaml]
volumeMounts:
– name: appconfs #通过挂载卷引用comfigmap
mountPath: /etc/envoy
readOnly: true
– name: demo
image: ikubernetes/demoapp:v1.0
imagePullPolicy: IfNotPresent
env: #通过环境变量引用 但这里引用的comfigmap文件中并没有定义
– name: PORT
valueFrom:
configMapKeyRef:
name: demoapp-confs
key: demoapp.port
optional: false
– name: HOST
valueFrom:
configMapKeyRef:
name: demoapp-confs
key: demoapp.host
optional: true
volumes:
– name: appconfs
configMap:
name: demoapp-confs #这里只引用的2个文件
items: #默认只允许哪些键 输出给存储卷
– key: envoy.yaml #挂载的键名
path: envoy.yaml #挂载的文件名 可以和上面不一样
mode: 0644 #挂载后的权限
– key: lds.conf
path: lds.conf
mode: 0644
optional: false
[root@k8s-master configmap]# kubectl create cm demoapp-confs –from-literal=demoapp.host=127.0.0.1 –from-literal=demoapp.port=”8080″ –from-file=./demoapp-conf.d/ #创建时定义demoapp.host、demoapp.port
[root@k8s-master ~]# kubectl describe cm demoapp-confs
Name: demoapp-confs
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
demoapp.host:
—-
127.0.0.1
demoapp.port:
—-
8080
envoy.yaml:
—-
node:
id: sidecar-proxy
cluster: demoapp-cluster
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
dynamic_resources:
lds_config:
path: /etc/envoy/lds.conf
static_resources:
clusters:
– name: local_service
connect_timeout: 0.25s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: local_service
endpoints:
– lb_endpoints:
– endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 8080
lds.conf:
—-
{
“version_info”: “0”,
“resources”: [
{
“@type”: “type.googleapis.com/envoy.api.v2.Listener”,
“name”: “listener_0”,
“address”: {
“socket_address”: {
“address”: “0.0.0.0”,
“port_value”: 80
}
},
“filter_chains”: [
{
“filters”: [
{
“name”: “envoy.http_connection_manager”,
“config”: {
“stat_prefix”: “ingress_http”,
“codec_type”: “AUTO”,
“route_config”: {
“name”: “local_route”,
“virtual_hosts”: [
{
“name”: “local_service”,
“domains”: [
“*”
],
“routes”: [
{
“match”: {
“prefix”: “/”
},
“route”: {
“cluster”: “local_service”
}
}
]
}
]
},
“http_filters”: [
{
“name”: “envoy.router”
}
]
}
}
]
}
]
}
]
}
Events: <none>
[root@k8s-master configmap]# kubectl apply -f configmaps-volume-demo2.yaml
pod/configmaps-volume-demo2 created
[root@k8s-master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
configmaps-volume-demo 1/1 Running 0 6h47m 10.244.1.177 k8s-node1 <none> <none>
configmaps-volume-demo2 2/2 Running 0 35m 10.244.1.182 k8s-node1 <none> <none>
my-grafana-7d788c5479-bpztz 1/1 Running 1 2d5h 10.244.2.120 k8s-node2 <none> <none>
volumes-pvc-longhorn-demo 1/1 Running 0 35h 10.244.2.124 k8s-node2 <none> <none>
[root@k8s-master ~]# kubectl exec configmaps-volume-demo2 -c demo — netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9901 0.0.0.0:* LISTEN –
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 1/python3
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN –
[root@k8s-master ~]# kubectl exec configmaps-volume-demo2 -c proxy — netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9901 0.0.0.0:* LISTEN 1/envoy
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/envoy
[root@k8s-master ~]# kubectl exec configmaps-volume-demo2 -c proxy — ls /etc/envoy
envoy.yaml
lds.conf