Openshift创建project时,可以按照设定的模板来创建,这就省去了很多初始化的工作。
###文件内容(template.yaml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
apiVersion: v1
kind: Template
metadata:
creationTimestamp: null
name: project-request
objects:
- apiVersion: v1
kind: Project
metadata:
annotations:
openshift.io/description: ${PROJECT_DESCRIPTION}
openshift.io/display-name: ${PROJECT_DISPLAYNAME}
openshift.io/requester: ${PROJECT_REQUESTING_USER}
creationTimestamp: null
name: ${PROJECT_NAME}
spec: {}
status: {}
- apiVersion: v1
kind: ResourceQuota
metadata:
name: ${PROJECT_NAME}-quota
spec:
hard:
pods: 10
requests.cpu: 4000m
requests.memory: 8Gi
resourcequotas: 1
requests.storage: 25Gi
persistentvolumeclaims: 5
- apiVersion: v1
kind: LimitRange
metadata:
name: ${PROJECT_NAME}-limits
creationTimestamp: null
spec:
limits:
-
type: Container
max:
cpu: 4000m
memory: 1024Mi
min:
cpu: 10m
memory: 5Mi
default:
cpu: 4000m
memory: 1024Mi
defaultRequest:
cpu: 100m
memory: 512Mi
- apiVersion: v1
groupNames:
- system:serviceaccounts:${PROJECT_NAME}
kind: RoleBinding
metadata:
creationTimestamp: null
name: system:image-pullers
namespace: ${PROJECT_NAME}
roleRef:
name: system:image-puller
subjects:
- kind: SystemGroup
name: system:serviceaccounts:${PROJECT_NAME}
userNames: null
- apiVersion: v1
groupNames: null
kind: RoleBinding
metadata:
creationTimestamp: null
name: system:image-builders
namespace: ${PROJECT_NAME}
roleRef:
name: system:image-builder
subjects:
- kind: ServiceAccount
name: builder
userNames:
- system:serviceaccount:${PROJECT_NAME}:builder
- apiVersion: v1
groupNames: null
kind: RoleBinding
metadata:
creationTimestamp: null
name: system:deployers
namespace: ${PROJECT_NAME}
roleRef:
name: system:deployer
subjects:
- kind: ServiceAccount
name: deployer
userNames:
- system:serviceaccount:${PROJECT_NAME}:deployer
- apiVersion: v1
groupNames: null
kind: RoleBinding
metadata:
creationTimestamp: null
name: admin
namespace: ${PROJECT_NAME}
roleRef:
name: admin
subjects:
- kind: User
name: ${PROJECT_ADMIN_USER}
userNames:
- ${PROJECT_ADMIN_USER}
parameters:
- name: PROJECT_NAME
- name: PROJECT_DISPLAYNAME
- name: PROJECT_DESCRIPTION
- name: PROJECT_ADMIN_USER
- name: PROJECT_REQUESTING_USER

将它导入模板

1
oc create -f template.yaml -n default

将它设为Project默认配置

1
2
3
4
5
#/etc/origin/master/master-config.yaml
...
projectConfig:
projectRequestTemplate: "default/project-request"
...

重启Master,使配置生效

1
sudo systemctl restart atomic-openshift-master

验证

1
oc new-project tem-test