You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CreationTimestamp: Wed, 13 Feb 2019 11:05:57 -0500
1046
+
----
1047
+
....
1048
+
1049
+
=== YAML formatting for Kubernetes and OpenShift API objects
1050
+
The following formatting guidelines apply to YAML manifests, but do not apply to the installation configuration YAML specified by `install-config.yaml`.
1051
+
1052
+
When possible, ensure that YAML is valid in a running cluster. You can validate YAML with `oc apply` with the following invocation:
1053
+
1054
+
----
1055
+
$ oc apply -f test.yaml --dry-run=client
1056
+
----
1057
+
1058
+
==== Required fields
1059
+
1060
+
- Include the `apiVersion` and `kind` so that a user always knows the context of the YAML.
1061
+
- Include the full hierarchy to a deeply nested key.
1062
+
- For objects that are in the global scope, such as for `config.openshift.io` API group, always include the `metadata.name` for the object, which is usually `cluster`.
1063
+
1064
+
.Example API object in the global scope
1065
+
----
1066
+
apiVersion: config.openshift.io/v1
1067
+
kind: Scheduler
1068
+
metadata:
1069
+
name: cluster
1070
+
...
1071
+
spec:
1072
+
defaultNodeSelector: node-role.kubernetes.io/app=
1073
+
...
1074
+
----
1075
+
1076
+
.Example deeply nested key with full context for `.ports` array
1077
+
----
1078
+
apiVersion: v1
1079
+
kind: Pod
1080
+
metadata:
1081
+
name: pod1
1082
+
namespace: default
1083
+
spec:
1084
+
containers:
1085
+
- name: web
1086
+
image: nginx
1087
+
ports:
1088
+
- name: web
1089
+
containerPort: 80
1090
+
protocol: TCP
1091
+
----
1092
+
1093
+
==== Formatting
1094
+
Use the following conventions govern the layout of YAML for API objects.
1095
+
1096
+
- Begin YAML at the beginning of the left margin.
1097
+
- Use two-space indentation.
1098
+
- Indent arrays at the same depth as the parent field.
1099
+
- Include a space immediately after the colon for keys.
1100
+
- Use block style for complex strings, such as embedded JSON or text blocks. You can enable block style by specifying `|` or `|-` after a field and indenting the field content by two spaces, such as in the following example:
1101
+
+
1102
+
----
1103
+
fieldName: |-
1104
+
This is a string.
1105
+
And it can be on multiple lines.
1106
+
----
1107
+
- When truncating YAML, always precede an ellipsis with a pound so that the YAML is valid.
1108
+
1109
+
.Example with array indentation flush with parent field
1110
+
----
1111
+
apiVersion: v1
1112
+
kind: Pod
1113
+
metadata:
1114
+
name: pod1
1115
+
labels:
1116
+
- key1: val1
1117
+
- key2: val2
1118
+
spec:
1119
+
...
1120
+
----
1121
+
1122
+
.Example with block string for annotation
1123
+
----
1124
+
apiVersion: v1
1125
+
kind: Pod
1126
+
metadata:
1127
+
name: pod1
1128
+
annotations:
1129
+
k8s.v1.cni.cncf.io/networks: |-
1130
+
[
1131
+
{
1132
+
"name": "net"
1133
+
}
1134
+
]
1135
+
spec:
1136
+
...
1137
+
----
1138
+
1020
1139
=== Inline code or commands
1021
1140
Do NOT show full commands or command syntax inline within a sentence. The next section covers how to show commands and command syntax.
0 commit comments