我使用 kops 在AWS中创建了一个八卦群集,这意味着我的群集名称以 k8s.local 结尾(要执行的clusters.test.k8s.local) , 一切正常,直到我尝试创建一个部署,其中pod名称最后需要一个域名(api-manager.iot.test.co.nz)。
我知道它没有被授权创建不符合此正则表达式的要求的pod:
'[a-z]([-a-z0-9]*[a-z0-9])?'
我有办法做到吗?
我尝试在template->规范下添加主机名,但它有相同的限制(正则表达式)。
这是我的部署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
答案 0 :(得分:0)
不,你不能按设计创造那种labels
。
从设计document:
rfc1035 / rfc1123
label
(DNS_LABEL):字母数字(az和0-9)字符串,最大长度为63个字符,允许使用“ - ”字符除第一个或最后一个字符以外的任何地方,适合用作域名中的主机名或段。
以下是当前implementation:
const dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
const dns1035LabelErrMsg string = "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character"
const DNS1035LabelMaxLength int = 63
var dns1035LabelRegexp = regexp.MustCompile("^" + dns1035LabelFmt + "$")
// IsDNS1035Label tests for a string that conforms to the definition of a label in
// DNS (RFC 1035).
func IsDNS1035Label(value string) []string {
var errs []string
if len(value) > DNS1035LabelMaxLength {
errs = append(errs, MaxLenError(DNS1035LabelMaxLength))
}
if !dns1035LabelRegexp.MatchString(value) {
errs = append(errs, RegexError(dns1035LabelErrMsg, dns1035LabelFmt, "my-name", "abc-123"))
}
return errs
}
答案 1 :(得分:0)
经过很多挣扎之后, 这是我的解决方案:
https://kubernetes.io/blog/2017/04/configuring-private-dns-zones-upstream-nameservers-kubernetes/
1。)使用您的域配置创建一个 dnsmasq ,您将必须附加一个群集IP,该IP必须在您使用的k8s群集的范围内。
这些是我为此创建的Yaml文件:
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。)使用stubDomain创建一个kube-dns配置图:
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-dns
namespace: kube-system
data:
stubDomains: |
{"iot.test.vector.co.nz": ["100.68.140.187"]}
3。)将我们在dns配置中定义的静态IP添加到out服务:
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