无法在OpenShift中创建Pod(runAsGroup与命名空间中的注释字段值不匹配)。

huangapple go评论103阅读模式
英文:

Not able to create pod in openshift (The runAsGroup does not match the field value from the annotation in the namespace)

问题

您正在尝试使用deploymentConfig部署一些应用程序。以下是用于PostgreSQL的YAML文件的简化版本。

  1. apiVersion: template.openshift.io/v1
  2. kind: Template
  3. labels:
  4. template: postgres
  5. message: |-
  6. 用于测试在Openshift上部署PostgreSQL
  7. metadata:
  8. annotations:
  9. description: Openshift上部署PostgreSQL
  10. openshift.io/display-name: PostgreSQL
  11. openshift.io/long-description: PostgreSQL
  12. openshift.io/provider-display-name: xxxx
  13. tags: 数据库
  14. template.openshift.io/bindable: "false"
  15. name: PostgreSQL
  16. objects:
  17. # 其他对象的部分未翻译
  18. # ...
  19. parameters:
  20. - description: 应用程序名称
  21. displayName: 应用程序名称
  22. name: APPLICATION_NAME
  23. value: postgres
  24. - description: PostgreSQL主机
  25. displayName: PostgreSQL主机名
  26. name: POSTGRESQL_HOST
  27. value: postgresql
  28. required: true
  29. - description: PostgreSQL连接用户名
  30. displayName: PostgreSQL连接用户名
  31. from: 'user[a-z0-9]{5}'
  32. generate: expression
  33. name: POSTGRESQL_USER
  34. required: true
  35. - description: PostgreSQL连接密码
  36. displayName: PostgreSQL连接密码
  37. from: '[a-zA-Z0-9]{16}'
  38. generate: expression
  39. name: POSTGRESQL_PASSWORD
  40. required: true
  41. - description: PostgreSQL数据库名称
  42. displayName: PostgreSQL连接数据库
  43. from: 'airflow[a-z0-9]{5}'
  44. generate: expression
  45. name: POSTGRESQL_DATABASE
  46. required: true
  47. - description: 用于存储PostgreSQL数据库中元数据的PERSISTENT卷声明名称
  48. displayName: PERSISTENT卷声明名称(数据库)
  49. name: PERSISTENT_VOLUME_CLAIM_DB
  50. value: storage-db-pvc
  51. - description: 元数据卷存储大小
  52. displayName: 元数据卷存储大小
  53. name: PERSISTENT_VOLUME_CLAIM_DB_SIZE
  54. value: "1Gi"

当我执行此模板时,我收到以下错误消息:

  1. 停止重试:无法为“zzzzzzzzzz/postgresql-7”创建部署器Pod:验证webhookvalidate.kyverno.something-ignore”拒绝了请求:策略Pod/namespace_name/postgresql-7-deploy违反了资源:add-securitycontextupdate-runasgrouprunAsGroup与命名空间中注释的字段值不匹配。ensure-readonly-lustreensure-readonly-lustre:未满足前提条件。

我已经重新检查了runAsUser和runAsGroup,并且根据SCC正确定义。是否有关于我的模板YAML的问题?

希望这有助于您解决问题。如果您需要更多帮助或建议,请告诉我。

英文:

I am trying to deploy some applications using deploymentConfig. Below is the simplified version of yaml file for postgres.

  1. apiVersion: template.openshift.io/v1
  2. kind: Template
  3. labels:
  4. template: postgres
  5. message: |-
  6. To test deployment for postgres.
  7. metadata:
  8. annotations:
  9. description: Deploys postgress on Openshift.
  10. openshift.io/display-name: postgress
  11. openshift.io/long-description: postgres
  12. openshift.io/provider-display-name: xxxx
  13. tags: database
  14. template.openshift.io/bindable: "false"
  15. name: postgres
  16. objects:
  17. - apiVersion: apps.openshift.io/v1
  18. kind: DeploymentConfig
  19. metadata:
  20. annotations:
  21. template.alpha.openshift.io/wait-for-ready: 'true'
  22. labels:
  23. app: ${APPLICATION_NAME}
  24. template: postgresql-ephemeral-template
  25. name: ${POSTGRESQL_HOST}
  26. spec:
  27. replicas: 1
  28. selector:
  29. name: ${POSTGRESQL_HOST}
  30. strategy:
  31. type: Recreate
  32. template:
  33. metadata:
  34. labels:
  35. name: ${POSTGRESQL_HOST}
  36. spec:
  37. containers:
  38. - env:
  39. - name: POSTGRESQL_USER
  40. valueFrom:
  41. secretKeyRef:
  42. key: database-user
  43. name: postgresql
  44. - name: POSTGRESQL_PASSWORD
  45. valueFrom:
  46. secretKeyRef:
  47. key: database-password
  48. name: postgresql
  49. - name: POSTGRESQL_DATABASE
  50. valueFrom:
  51. secretKeyRef:
  52. key: database-name
  53. name: postgresql
  54. image: rhel8/postgresql-12
  55. imagePullPolicy: IfNotPresent
  56. livenessProbe:
  57. exec:
  58. command:
  59. - "/usr/libexec/check-container"
  60. - "--live"
  61. initialDelaySeconds: 120
  62. timeoutSeconds: 10
  63. name: ${POSTGRESQL_HOST}
  64. ports:
  65. - containerPort: 5432
  66. protocol: TCP
  67. readinessProbe:
  68. exec:
  69. command:
  70. - "/usr/libexec/check-container"
  71. initialDelaySeconds: 5
  72. timeoutSeconds: 1
  73. resources:
  74. limits:
  75. memory: 1Gi
  76. securityContext:
  77. capabilities: {}
  78. privileged: false
  79. terminationMessagePath: /dev/termination-log
  80. volumeMounts:
  81. - mountPath: /var/lib/pgsql/data
  82. name: postgresql-data
  83. dnsPolicy: ClusterFirst
  84. restartPolicy: Always
  85. schedulerName: default-scheduler
  86. securityContext:
  87. runAsUser: 2222
  88. runAsGroup: 1111
  89. terminationGracePeriodSeconds: 30
  90. volumes:
  91. - name: postgresql-data
  92. persistentVolumeClaim:
  93. claimName: ${PERSISTENT_VOLUME_CLAIM_DB}
  94. triggers:
  95. - imageChangeParams:
  96. automatic: true
  97. containerNames:
  98. - ${POSTGRESQL_HOST}
  99. from:
  100. kind: ImageStreamTag
  101. name: postgresql:12
  102. namespace: airflow-data-factory
  103. type: ImageChange
  104. - type: ConfigChange
  105. - apiVersion: v1
  106. stringData:
  107. database-name: ${POSTGRESQL_DATABASE}
  108. database-password: ${POSTGRESQL_PASSWORD}
  109. database-user: ${POSTGRESQL_USER}
  110. connection-string: postgresql+psycopg2://${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:5432/${POSTGRESQL_DATABASE}
  111. result-backend: db+postgresql://${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:5432/${POSTGRESQL_DATABASE}
  112. kind: Secret
  113. metadata:
  114. labels:
  115. app: ${APPLICATION_NAME}
  116. template: postgresql-ephemeral-template
  117. name: postgresql
  118. type: Opaque
  119. - apiVersion: v1
  120. kind: Service
  121. metadata:
  122. labels:
  123. app: ${APPLICATION_NAME}
  124. template: postgresql-ephemeral-template
  125. name: ${POSTGRESQL_HOST}
  126. spec:
  127. ports:
  128. - name: ${POSTGRESQL_HOST}
  129. port: 5432
  130. protocol: TCP
  131. targetPort: 5432
  132. selector:
  133. name: ${POSTGRESQL_HOST}
  134. sessionAffinity: None
  135. type: ClusterIP
  136. status:
  137. loadBalancer: {}
  138. - apiVersion: v1
  139. kind: PersistentVolumeClaim
  140. metadata:
  141. name: ${PERSISTENT_VOLUME_CLAIM_DB}
  142. namespace: airflow-data-factory
  143. spec:
  144. storageClassName: openshift-trident-ext4
  145. accessModes:
  146. - "ReadWriteOnce"
  147. resources:
  148. requests:
  149. storage: ${PERSISTENT_VOLUME_CLAIM_DB_SIZE}
  150. parameters:
  151. - description: Name of the application
  152. displayName: Application name
  153. name: APPLICATION_NAME
  154. value: postgres
  155. - description: PostgreSQL host
  156. displayName: PostgreSQL hostname
  157. name: POSTGRESQL_HOST
  158. value: postgresql
  159. required: true
  160. - description: Username for PostgreSQL user that will be used for accessing the database
  161. displayName: PostgreSQL connection username
  162. from: 'user[a-z0-9]{5}'
  163. generate: expression
  164. name: POSTGRESQL_USER
  165. required: true
  166. - description: Password for the PostgreSQL connection user
  167. displayName: PostgreSQL connection password
  168. from: '[a-zA-Z0-9]{16}'
  169. generate: expression
  170. name: POSTGRESQL_PASSWORD
  171. required: true
  172. - description: Database name for PostgreSQL database
  173. displayName: PostgreSQL connection database
  174. from: 'airflow[a-z0-9]{5}'
  175. generate: expression
  176. name: POSTGRESQL_DATABASE
  177. required: true
  178. - description: Attached PERSISTENT volume claim name for storing metadata in PostgreSQL database
  179. displayName: PERSISTENT volume claim name (database)
  180. name: PERSISTENT_VOLUME_CLAIM_DB
  181. value: storage-db-pvc
  182. - description: Size of the metadata volume storage
  183. displayName: Metadata volume storage size
  184. name: PERSISTENT_VOLUME_CLAIM_DB_SIZE
  185. value: "1Gi"

When I execute this template, I am getting following error:

  1. Stop retrying: couldn't create deployer pod for "zzzzzzzzzz/postgresql-7": admission webhook "validate.kyverno.something-ignore" denied the request: policy Pod/namespace_name/postgresql-7-deploy for resource violations: add-securitycontext: update-runasgroup: The runAsGroup does not match the field value from the annotation in the namespace. ensure-readonly-lustre: ensure-readonly-lustre: preconditions not met

I have rechecked runAsUser and runAsGroup. And it is defined correctly according to scc.
Any help or suggestions would be greatly welcomed.

it failed with error to update runAsGroup but i am sure that it is correct. Is there amy problem with my template yaml?

答案1

得分: 0

"Basically, runAsUser and runAsGroup violate OpenShift policies. In other words, you can't use them with OpenShift.

What is happening in OpenShift, it creates a random (big number, always >1000) user id which runs your pod and assigns it to the root group (id 0).

So you need to adjust your images so that permissions allow to run it by someone belonging to the root group.

Now, for your particular case, start with removing securityContext completely and see what happens - it may just work as is. If not, look at what resources need access by the user running the container and make sure they are accessible by a user with groupid 0."

英文:

Basically, runAsUser and runAsGroup violate OpenShift policies. In other words, you can't use them with OpenShift.

What is happening in OpenShift, it creates a random (big number, always >1000) user id which runs your pod and assigns it to the root group (id 0).

So you need to adjust your images so that permissions allow to run it by someone belonging to the root group.

Now, for your particular case, start with removing securityContext completely and see what happens - it may just work as is. If not, look at what resources need access by the user running the container and make sure they are accessible by a user with groupid 0.

huangapple
  • 本文由 发表于 2023年4月19日 21:44:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定