kubernetes - kubernetes 最后创建一个带域的服务
问题描述
我使用kops在 AWS 中创建了一个 gossip 集群,这意味着我的集群名称以k8s.local结尾(要执行的 clusters.test.k8s.local ),在我尝试创建需要 pod 名称的部署之前,一切正常最后是一个域(api-manager.iot.test.co.nz)。
我知道它无权创建不在此正则表达式要求中的 pod:
'[a-z]([-a-z0-9]*[a-z0-9])?'
有没有办法我可以做到这一点?
我尝试在 template->spec 下添加主机名,但它具有相同的限制(正则表达式)。
这是我的部署 YAML 文件:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
labels:
name: api-manager
spec:
replicas: 1
template:
metadata:
labels:
app: api-manager
spec:
volumes:
- name: api-manager-efs
persistentVolumeClaim:
claimName: pvc-apim
containers:
- image: api-manager:2.1.0
name: api-manager.iot.test.co.nz
ports:
- name: porta
containerPort: 9763
- name: portb
containerPort: 9443
env:
- name: SLEEP
value: "30"
volumeMounts:
- name: api-manager-efs
mountPath: /home/wso2carbon/wso2am-2.1.0/repository
解决方案
after a lot of struggling, This is my solution:
https://kubernetes.io/blog/2017/04/configuring-private-dns-zones-upstream-nameservers-kubernetes/
1.) create a dnsmasq with this your domain configuration inside, you will have to attach a cluster IP which must be in the range of your k8s cluster that you use.
These are the yaml files I created for that:
apiVersion: v1
kind: ConfigMap
metadata:
name: dnsmasq
labels:
app: dnsmasq
data:
dnsmasq.conf: |+
user=root
#dnsmasq config, for a complete example, see:
# http://oss.segetech.com/intra/srv/dnsmasq.conf
#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
#use google as default nameservers
server=8.8.4.4
server=8.8.8.8
#serve all .company queries using a specific nameserver
server=/company/10.0.0.1
#explicitly define host-ip mappings
address=/api-manager.iot.test.vector.co.nz/100.64.53.55
apiVersion: v1
kind: Service
metadata:
labels:
app: dnsmasq
name: dnsstub
spec:
type: "{{.Values.Service.serviceType}}"
clusterIP: 100.68.140.187
ports:
- port: {{ .Values.Service.serviceports.port }}
protocol: UDP
selector:
app: dnsmasq
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: dnsmasq
spec:
replicas: {{ .Values.Deployment.replicaCount }}
template:
metadata:
labels:
app: dnsmasq
spec:
containers:
- name: dnsmasq
image: dnsmasq:1.0.2
ports:
- containerPort: {{ .Values.Deployment.ports.containerport }}
protocol: UDP
volumeMounts:
- name: etc
mountPath: /etc/dnsmasq.conf
subPath: dnsmasq.conf
imagePullSecrets:
- name: mprestg-credentials
volumes:
- name: etc
configMap:
name: dnsmasq
dnsPolicy: Default
2.) Create a kube-dns config-map with stubDomain:
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-dns
namespace: kube-system
data:
stubDomains: |
{"iot.test.vector.co.nz": ["100.68.140.187"]}
3.) Add the static IP that we defined in our dns configuration to out service:
apiVersion: v1
kind: Service
metadata:
name: api-manager
labels:
app: api-manager
tier: apim
spec:
ports:
- port: 9763
name: porta
targetPort: 9763
selector:
app: api-manager
type: LoadBalancer
clusterIP: 100.64.53.55
推荐阅读
- linux - LED 通过 Rpi Linux 设备驱动程序闪烁
- python - DNSpython 会使用缓存吗?
- angular - Angular: Close a MatDialog
- javascript - 纯 Javascript 全色谱 ColorPicker
- sql - 按日期在分组集中复制具有多个组的分组集的值
- python-3.x - 尝试使用 Raspberry pi 3 读取电机值
- charts - 如何实现居中折线图?
- typescript - Webpack,babel - node_modules 不排除在捆绑包中
- reactjs - 进行选择后隐藏或最小化搜索构面组件
- css - 具有唯一行名的网格重复