a DNS-1123 label must consist of lower case alphanumeric characters or ‘-‘, and must start and end w

Posted mry6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了a DNS-1123 label must consist of lower case alphanumeric characters or ‘-‘, and must start and end w相关的知识,希望对你有一定的参考价值。

a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character

报错信息

[root@master]# kubectl create -f zuizhong.yaml 
Error from server (Invalid): error when creating "zuizhong.yaml": Deployment.apps "mry" is invalid: spec.template.spec.containers[2].name: Invalid value: "mry_backend": a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
Error from server (Invalid): error when creating "zuizhong.yaml": Service "mry-service" is invalid: spec.ports[2].name: Invalid value: "mry_backend": a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')

错误原因

kubernetes中对资源命名时注意不能使用下划线

样例内容

错误样例:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mry
  labels:
    mrn: mry
spec:
  replicas: 1
  selector:
    matchLabels:
      mrn: mry
  template:
    metadata:
      labels:
        mrn: mry
    spec:
      containers:
        - name: mry-redis
          image: redis:5.0.12
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 6379
        - name: mry-nginx
          image: nginx:1.17.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
        - name: mry_backend
          image: tomcat:8
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          volumeMounts:
            - mountPath: /home/mrn/volumes/mry
              name: mry
      volumes:
      - name: mry
        hostPath:
          path: /home/mrn/volumes/mry

---
apiVersion: v1
kind: Service
metadata:
  name: mry-service
spec:
  ports:
    - port: 6379
      targetPort: 6379
      protocol: TCP
      name: mry-redis
      nodePort: 30010
    - port: 80
      targetPort: 80
      protocol: TCP
      name: mry-nginx
      nodePort: 30011
    - port: 8080
      targetPort: 8080
      protocol: TCP
      name: mry_backend
      nodePort: 30012
  selector:
    mrn: mry
  type: NodePort

修改成中划线:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mry
  labels:
    mrn: mry
spec:
  replicas: 1
  selector:
    matchLabels:
      mrn: mry
  template:
    metadata:
      labels:
        mrn: mry
    spec:
      containers:
        - name: mry-redis
          image: redis:5.0.12
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 6379
        - name: mry-nginx
          image: nginx:1.17.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
        - name: mry-backend
          image: tomcat:8
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          volumeMounts:
            - mountPath: /home/mrn/volumes/mry
              name: mry
      volumes:
      - name: mry
        hostPath:
          path: /home/mrn/volumes/mry

---
apiVersion: v1
kind: Service
metadata:
  name: mry-service
spec:
  ports:
    - port: 6379
      targetPort: 6379
      protocol: TCP
      name: mry-redis
      nodePort: 30010
    - port: 80
      targetPort: 80
      protocol: TCP
      name: mry-nginx
      nodePort: 30011
    - port: 8080
      targetPort: 8080
      protocol: TCP
      name: mry-backend
      nodePort: 30012
  selector:
    mrn: mry
  type: NodePort
创作挑战赛 新人创作奖励来咯,坚持创作打卡瓜分现金大奖

以上是关于a DNS-1123 label must consist of lower case alphanumeric characters or ‘-‘, and must start and end w的主要内容,如果未能解决你的问题,请参考以下文章

Error: label vector and instance matrix must be double的解决方法

ValueError: Bin labels must be one fewer than the number of bin edges

Hint: Fallback method 'public java.lang.String queryUserByIdFallback(java.lang.Long)' must r

colMedians(x) : Argument ‘x’ must be a matrixrowMedians(data) : Argument ‘x‘ must be a matrix.

7 Must Read Python Books

PHP:Function name must be a string in...求解,难道后台不能这样写?