Skip to content

Commit 4df0348

Browse files
committed
feat: add OCI CAPI
adds CAPI for OCI
1 parent 50a1137 commit 4df0348

File tree

2 files changed

+311
-0
lines changed

2 files changed

+311
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#+title: OCI CAPI cluster
2+
3+
Bring up Kubernetes locally
4+
5+
#+begin_src bash
6+
kind create cluster
7+
#+end_src
8+
9+
#+begin_src bash :tangle .envrc
10+
[ ! -f priv.env ] || . priv.env
11+
# export OCI_TENANCY_ID=
12+
# export OCI_USER_ID=
13+
# export OCI_CREDENTIALS_FINGERPRINT=
14+
# export OCI_CREDENTIALS_KEY_B64= # $(base64 < path/to/a/key.pem | tr -d '\n')
15+
export OCI_REGION=us-sanjose-1
16+
17+
export OCI_TENANCY_ID_B64="$(echo -n "$OCI_TENANCY_ID" | base64 | tr -d '\n')"
18+
export OCI_CREDENTIALS_FINGERPRINT_B64="$(echo -n "$OCI_CREDENTIALS_FINGERPRINT" | base64 | tr -d '\n')"
19+
export OCI_USER_ID_B64="$(echo -n "$OCI_USER_ID" | base64 | tr -d '\n')"
20+
export OCI_REGION_B64="$(echo -n "$OCI_REGION" | base64 | tr -d '\n')"
21+
22+
# if bootstraping from inside OCI
23+
export USE_INSTANCE_PRINCIPAL="false"
24+
export USE_INSTANCE_PRINCIPAL_B64="$(echo -n "$USE_INSTANCE_PRINCIPAL" | base64 | tr -d '\n')"
25+
#+end_src
26+
27+
allow env from .envrc
28+
29+
#+begin_src bash
30+
direnv allow
31+
#+end_src
32+
33+
bootstrap capi with oci
34+
35+
#+begin_src bash
36+
clusterctl init -b talos:v0.6.5 -c talos:v0.5.6 --infrastructure oci:v0.16.0
37+
#+end_src
38+
39+
create a namespace
40+
41+
#+begin_src bash
42+
kubectl create ns sharingio
43+
#+end_src
44+
45+
#+RESULTS:
46+
#+begin_example
47+
namespace/sharingio created
48+
#+end_example
49+
50+
Generate a cluster config
51+
52+
#+begin_src bash :tangle .envrc
53+
# export OCI_COMPARTMENT_ID=
54+
# export OCI_IMAGE_ID=ocid1.image.oc1.us-sanjose-1.aaaaaaaazpwpyk7kh6mbu2g6yihups2zf5uwt7moehbafxsu4idaew6nggxq # NOTE Oracle 8
55+
export OCI_IMAGE_ID=ocid1.image.oc1.us-sanjose-1.aaaaaaaaqemyxu4dnhuapt6dfzuhq6rp5h3f7ld3yqh3crwiu5qtzlk6woma
56+
export OCI_CONTROL_PLANE_MACHINE_TYPE=VM.Standard.A1.Flex
57+
export OCI_CONTROL_PLANE_MACHINE_TYPE_OCPUS=4
58+
export OCI_NODE_MACHINE_TYPE=VM.Standard.A1.Flex
59+
export OCI_NODE_MACHINE_TYPE_OCPUS=8
60+
export OCI_SSH_KEY=
61+
export OCI_CONTROL_PLANE_PV_TRANSIT_ENCRYPTION=true
62+
export OCI_NODE_PV_TRANSIT_ENCRYPTION=true
63+
64+
export TALOS_INSTALL_IMAGE=factory.talos.dev/installer/d01e4eb407f9a242831748cab07de55550fdcfe8be65ce4defd258a93d94562f:v1.7.6
65+
export CLUSTER_NAME=sharingio
66+
export CONTROL_PLANE_MACHINE_COUNT=3
67+
export KUBERNETES_VERSION=v1.30.1
68+
export NAMESPACE=sharingio
69+
export POD_CIDR=192.168.0.0/16
70+
export SERVICE_CIDR=10.128.0.0/12
71+
export NODE_MACHINE_COUNT=6
72+
73+
#+end_src
74+
75+
generate a cluster config
76+
77+
#+begin_src bash
78+
clusterctl -n sharingio generate cluster "$CLUSTER_NAME" --from ./cluster-template.yaml --write-to ./cluster.yaml
79+
#+end_src
80+
81+
#+RESULTS:
82+
#+begin_example
83+
#+end_example
84+
85+
apply the cluster
86+
87+
#+begin_src bash
88+
kubectl -n sharingio apply -f ./cluster.yaml
89+
#+end_src
90+
91+
#+RESULTS:
92+
#+begin_example
93+
cluster.cluster.x-k8s.io/sharingio created
94+
ocicluster.infrastructure.cluster.x-k8s.io/sharingio created
95+
taloscontrolplane.controlplane.cluster.x-k8s.io/sharingio-control-plane created
96+
ocimachinetemplate.infrastructure.cluster.x-k8s.io/sharingio-control-plane created
97+
ocimachinetemplate.infrastructure.cluster.x-k8s.io/sharingio-md-0 created
98+
talosconfigtemplate.bootstrap.cluster.x-k8s.io/sharingio-md-0 created
99+
machinedeployment.cluster.x-k8s.io/sharingio-md-0 created
100+
#+end_example
101+
102+
view the world
103+
104+
#+begin_src shell
105+
kubectl -n sharingio get $(kubectl -n sharingio api-resources | grep x-k8s | awk '{print $1}' | tr '\n' ',' | sed 's/,$//g')
106+
#+end_src
107+
108+
#+RESULTS:
109+
#+begin_example
110+
NAME AGE
111+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-2zps4 50s
112+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-8ts94 50s
113+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-frc97 50s
114+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-j77b6 50s
115+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-mbcs8 50s
116+
talosconfig.bootstrap.cluster.x-k8s.io/sharingio-md-0-gjmhg-w847p 50s
117+
118+
NAME AGE
119+
talosconfigtemplate.bootstrap.cluster.x-k8s.io/sharingio-md-0 85s
120+
121+
NAME CLUSTERCLASS PHASE AGE VERSION
122+
cluster.cluster.x-k8s.io/sharingio Provisioned 72s
123+
124+
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
125+
machinedeployment.cluster.x-k8s.io/sharingio-md-0 sharingio 6 6 6 ScalingUp 71s v1.30.1
126+
127+
NAME CLUSTER NODENAME PROVIDERID PHASE AGE VERSION
128+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-2zps4 sharingio Pending 50s v1.30.1
129+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-8ts94 sharingio Pending 50s v1.30.1
130+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-frc97 sharingio Pending 50s v1.30.1
131+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-j77b6 sharingio Pending 50s v1.30.1
132+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-mbcs8 sharingio Pending 50s v1.30.1
133+
machine.cluster.x-k8s.io/sharingio-md-0-gjmhg-w847p sharingio Pending 50s v1.30.1
134+
135+
NAME CLUSTER REPLICAS READY AVAILABLE AGE VERSION
136+
machineset.cluster.x-k8s.io/sharingio-md-0-gjmhg sharingio 6 50s v1.30.1
137+
138+
NAME READY INITIALIZED REPLICAS READY REPLICAS UNAVAILABLE REPLICAS
139+
taloscontrolplane.controlplane.cluster.x-k8s.io/sharingio-control-plane
140+
141+
NAME AGE
142+
ocicluster.infrastructure.cluster.x-k8s.io/sharingio 56s
143+
144+
NAME AGE
145+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-2zps4 50s
146+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-8ts94 50s
147+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-frc97 50s
148+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-j77b6 50s
149+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-mbcs8 50s
150+
ocimachine.infrastructure.cluster.x-k8s.io/sharingio-md-0-gjmhg-w847p 50s
151+
152+
NAME AGE
153+
ocimachinetemplate.infrastructure.cluster.x-k8s.io/sharingio-control-plane 56s
154+
ocimachinetemplate.infrastructure.cluster.x-k8s.io/sharingio-md-0 56s
155+
#+end_example
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
apiVersion: cluster.x-k8s.io/v1beta1
3+
kind: Cluster
4+
metadata:
5+
labels:
6+
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
7+
name: ${CLUSTER_NAME}
8+
namespace: sharingio
9+
spec:
10+
clusterNetwork:
11+
pods:
12+
cidrBlocks:
13+
- ${POD_CIDR}
14+
serviceDomain: cluster.local
15+
services:
16+
cidrBlocks:
17+
- ${SERVICE_CIDR}
18+
controlPlaneRef:
19+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
20+
kind: TalosControlPlane
21+
name: ${CLUSTER_NAME}-control-plane
22+
namespace: sharingio
23+
infrastructureRef:
24+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
25+
kind: OCICluster
26+
name: ${CLUSTER_NAME}
27+
namespace: sharingio
28+
---
29+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
30+
kind: OCICluster
31+
metadata:
32+
labels:
33+
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
34+
name: ${CLUSTER_NAME}
35+
namespace: sharingio
36+
spec:
37+
compartmentId: ${OCI_COMPARTMENT_ID}
38+
---
39+
kind: TalosControlPlane
40+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
41+
metadata:
42+
name: "${CLUSTER_NAME}-control-plane"
43+
namespace: sharingio
44+
spec:
45+
version: ${KUBERNETES_VERSION}
46+
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
47+
infrastructureTemplate:
48+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
49+
kind: OCIMachineTemplate
50+
name: "${CLUSTER_NAME}-control-plane"
51+
controlPlaneConfig:
52+
controlplane:
53+
generateType: controlplane
54+
configPatches:
55+
- op: replace
56+
path: /machine/install
57+
value:
58+
disk: /dev/sda
59+
image: ${TALOS_INSTALL_IMAGE}
60+
bootloader: true
61+
wipe: false
62+
- op: add
63+
path: /machine/kubelet/extraArgs
64+
value:
65+
cloud-provider: external
66+
provider-id: oci://{{ ds["id"] }}
67+
- op: add
68+
path: /cluster/apiServer/extraArgs
69+
value:
70+
cloud-provider: external
71+
- op: add
72+
path: /cluster/controllerManager/extraArgs
73+
value:
74+
cloud-provider: external
75+
- op: add
76+
path: /cluster/allowSchedulingOnMasters
77+
value: true
78+
# - op: add
79+
# path: /cluster/extraManifests
80+
# value: []
81+
---
82+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
83+
kind: OCIMachineTemplate
84+
metadata:
85+
name: ${CLUSTER_NAME}-control-plane
86+
namespace: sharingio
87+
spec:
88+
template:
89+
spec:
90+
compartmentId: ${OCI_COMPARTMENT_ID}
91+
# imageId: ocid1.image.oc1.us-sanjose-1.aaaaaaaazpwpyk7kh6mbu2g6yihups2zf5uwt7moehbafxsu4idaew6nggxq # NOTE Oracle 8
92+
imageId: ${OCI_IMAGE_ID}
93+
isPvEncryptionInTransitEnabled: ${OCI_CONTROL_PLANE_PV_TRANSIT_ENCRYPTION}
94+
metadata:
95+
ssh_authorized_keys: ""
96+
shape: ${OCI_CONTROL_PLANE_MACHINE_TYPE}
97+
shapeConfig:
98+
ocpus: "${OCI_CONTROL_PLANE_MACHINE_TYPE_OCPUS}"
99+
networkDetails:
100+
assignPublicIp: true
101+
---
102+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
103+
kind: OCIMachineTemplate
104+
metadata:
105+
name: ${CLUSTER_NAME}-md-0
106+
namespace: sharingio
107+
spec:
108+
template:
109+
spec:
110+
compartmentId: ${OCI_COMPARTMENT_ID}
111+
# imageId: ocid1.image.oc1.us-sanjose-1.aaaaaaaazpwpyk7kh6mbu2g6yihups2zf5uwt7moehbafxsu4idaew6nggxq # NOTE Oracle 8
112+
imageId: ${OCI_IMAGE_ID}
113+
isPvEncryptionInTransitEnabled: ${OCI_NODE_PV_TRANSIT_ENCRYPTION}
114+
metadata:
115+
ssh_authorized_keys: ""
116+
shape: ${OCI_NODE_MACHINE_TYPE}
117+
shapeConfig:
118+
ocpus: "${OCI_NODE_MACHINE_TYPE_OCPUS}"
119+
networkDetails:
120+
assignPublicIp: true
121+
---
122+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
123+
kind: TalosConfigTemplate
124+
metadata:
125+
name: ${CLUSTER_NAME}-md-0
126+
namespace: sharingio
127+
labels:
128+
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
129+
spec:
130+
template:
131+
spec:
132+
generateType: join
133+
---
134+
apiVersion: cluster.x-k8s.io/v1beta1
135+
kind: MachineDeployment
136+
metadata:
137+
name: ${CLUSTER_NAME}-md-0
138+
namespace: sharingio
139+
spec:
140+
clusterName: ${CLUSTER_NAME}
141+
replicas: ${NODE_MACHINE_COUNT}
142+
selector:
143+
matchLabels: null
144+
template:
145+
spec:
146+
bootstrap:
147+
configRef:
148+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
149+
kind: TalosConfigTemplate
150+
name: ${CLUSTER_NAME}-md-0
151+
clusterName: ${CLUSTER_NAME}
152+
infrastructureRef:
153+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
154+
kind: OCIMachineTemplate
155+
name: ${CLUSTER_NAME}-md-0
156+
version: ${KUBERNETES_VERSION}

0 commit comments

Comments
 (0)