/
composition.yaml
299 lines (299 loc) · 11.5 KB
/
composition.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Composition of CAPI components and Helm ProviderConfig
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: Composition
metadata:
name: packet.cluster.capi.crossplane.io
labels:
provider: packet
spec:
writeConnectionSecretsToNamespace: crossplane-system
compositeTypeRef:
apiVersion: cluster.capi.crossplane.io/v1alpha1
kind: Cluster
resources:
- base:
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: KubeadmControlPlane
metadata:
name: capi-quickstart-control-plane
namespace: default
spec:
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachineTemplate
name: capi-quickstart-control-plane
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
extraArgs:
cloud-provider: external
controllerManager:
extraArgs:
cloud-provider: external
initConfiguration:
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
postKubeadmCommands:
- |
cat <<EOF >> /etc/network/interfaces
auto lo:0
iface lo:0 inet static
address {{ .controlPlaneEndpoint }}
netmask 255.255.255.255
EOF
- systemctl restart networking
- PROJECT_ID=replaceme
- 'kubectl --kubeconfig /etc/kubernetes/admin.conf create secret generic -n kube-system packet-cloud-config --from-literal=cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}", "eipTag": "cluster-api-provider-packet:cluster-id:capi-quickstart"}'''
- kubectl apply --kubeconfig /etc/kubernetes/admin.conf -f https://github.com/packethost/packet-ccm/releases/download/v1.1.0/deployment.yaml
preKubeadmCommands:
- sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
- swapoff -a
- mount -a
- apt-get -y update
- DEBIAN_FRONTEND=noninteractive apt-get install -y apt-transport-https curl
- curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- apt-key fingerprint 0EBFCD88
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update -y
- TRIMMED_KUBERNETES_VERSION=$(echo v1.18.2 | sed 's/\./\./g' | sed 's/^v//')
- RESOLVED_KUBERNETES_VERSION=$(apt-cache policy kubelet | awk -v VERSION=${TRIMMED_KUBERNETES_VERSION} '$1~ VERSION { print $1 }' | head -n1)
- apt-get install -y ca-certificates socat jq ebtables apt-transport-https cloud-utils prips docker-ce docker-ce-cli containerd.io kubelet=${RESOLVED_KUBERNETES_VERSION} kubeadm=${RESOLVED_KUBERNETES_VERSION} kubectl=${RESOLVED_KUBERNETES_VERSION}
- systemctl daemon-reload
- systemctl enable docker
- systemctl start docker
- ping -c 3 -q {{ .controlPlaneEndpoint }} && echo OK || ip addr add {{ .controlPlaneEndpoint }} dev lo
replicas: 3
version: v1.18.2
patches:
# These kind to metadata.name transforms are a hack to preserve the
# resultant object name. This means that only one CAPI Cluster can be
# created using this composition. We must do this because CAPI types
# don't allow for referencing other types by matchControllerRef
# (https://doc.crds.dev/github.com/packethost/crossplane-provider-packet/ports.metal.equinix.com/Assignment/v1alpha1#spec-forProvider-deviceIdSelector-matchControllerRef).
# We could improve the situation by still patching the names with a
# predictable output, and using that same patch in the references.
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart-control-plane
- fromFieldPath: spec.projectId
toFieldPath: spec.kubeadmConfigSpec.postKubeadmCommands[2]
transforms:
- type: string
string:
fmt: "PROJECT_ID=%s"
readinessChecks:
- type: None
- base:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachineTemplate
metadata:
name: capi-quickstart-control-plane
namespace: default
spec:
template:
spec:
OS: ubuntu_18_04
billingCycle: hourly
machineType: t1.small
sshKeys:
- my-ssh
tags: []
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart-control-plane
readinessChecks:
- type: None
- base:
apiVersion: cluster.x-k8s.io/v1alpha3
kind: Cluster
metadata:
name: capi-quickstart
namespace: default
spec:
clusterNetwork:
pods:
cidrBlocks:
- 192.168.0.0/16
services:
cidrBlocks:
- 172.26.0.0/16
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: KubeadmControlPlane
name: capi-quickstart-control-plane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketCluster
name: capi-quickstart
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart
readinessChecks:
- type: None
- base:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketCluster
metadata:
name: capi-quickstart
namespace: default
spec:
facility: ewr1
projectID: 5yd4thd-5h35-5hwk-1111-125gjej40930
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart
- fromFieldPath: spec.projectId
toFieldPath: spec.projectID
readinessChecks:
- type: None
- base:
apiVersion: cluster.x-k8s.io/v1alpha3
kind: MachineDeployment
metadata:
labels:
cluster.x-k8s.io/cluster-name: capi-quickstart
pool: worker-a
name: capi-quickstart-worker-a
namespace: default
spec:
clusterName: capi-quickstart
replicas: 3
selector:
matchLabels:
cluster.x-k8s.io/cluster-name: capi-quickstart
pool: worker-a
template:
metadata:
labels:
cluster.x-k8s.io/cluster-name: capi-quickstart
pool: worker-a
spec:
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: KubeadmConfigTemplate
name: capi-quickstart-worker-a
clusterName: capi-quickstart
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachineTemplate
name: capi-quickstart-worker-a
version: v1.18.2
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart-worker-a
readinessChecks:
- type: None
- base:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachineTemplate
metadata:
name: capi-quickstart-worker-a
namespace: default
spec:
template:
spec:
OS: ubuntu_18_04
billingCycle: hourly
machineType: t1.small
sshKeys:
- my-ssh
tags: []
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart-worker-a
readinessChecks:
- type: None
- base:
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: KubeadmConfigTemplate
metadata:
name: capi-quickstart-worker-a
namespace: default
spec:
template:
spec:
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
preKubeadmCommands:
- sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
- swapoff -a
- mount -a
- apt-get -y update
- DEBIAN_FRONTEND=noninteractive apt-get install -y apt-transport-https curl
- curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- apt-key fingerprint 0EBFCD88
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update -y
- TRIMMED_KUBERNETES_VERSION=$(echo v1.18.2 | sed 's/\./\./g' | sed 's/^v//')
- RESOLVED_KUBERNETES_VERSION=$(apt-cache policy kubelet | awk -v VERSION=${TRIMMED_KUBERNETES_VERSION} '$1~ VERSION { print $1 }' | head -n1)
- apt-get install -y ca-certificates socat jq ebtables apt-transport-https cloud-utils prips docker-ce docker-ce-cli containerd.io kubelet=${RESOLVED_KUBERNETES_VERSION} kubeadm=${RESOLVED_KUBERNETES_VERSION} kubectl=${RESOLVED_KUBERNETES_VERSION}
- systemctl daemon-reload
- systemctl enable docker
- systemctl start docker
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
Cluster: capi-quickstart-worker-a
readinessChecks:
- type: None
- base:
apiVersion: helm.crossplane.io/v1alpha1
kind: ProviderConfig
spec:
credentials:
source: Secret
secretRef:
# This ProviderConfig uses the above CAPI cluster's kubeconfig as
# its credentials secret. This another place that we could
# parameterize the name.
namespace: default
key: capi-quickstart-kubeconfig
patches:
- fromFieldPath: kind
toFieldPath: metadata.name
transforms:
- type: map
map:
# Setting name to default will make it default ProviderConfig
# for any Helm Release.
Cluster: default
readinessChecks:
- type: None