Skip to content

Commit 7d397d9

Browse files
authored
docs: add getting started tutorial (#94)
1 parent ecc9704 commit 7d397d9

File tree

16 files changed

+1094
-15
lines changed

16 files changed

+1094
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ coverage.xml
3131
*.swo
3232
*~
3333

34+
# Python virtualenv
35+
examples/getting-started/app/env
36+
3437
.vscode/

charts/mcs-controller-manager/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ helm upgrade mcs-controller-manager ./charts/mcs-controller-manager/
4747
| affinity | The node affinity to use for pod scheduling | `{}` |
4848
| tolerations | The toleration to use for pod scheduling | `[]` |
4949

50-
## Contributing Changes
50+
## Contributing Changes

examples/getting-started/README.md

Lines changed: 684 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3
2+
3+
RUN mkdir -p /workplace/app
4+
ADD main.py /workplace/app
5+
ADD requirements.txt /workplace/app
6+
7+
WORKDIR /workplace/app
8+
RUN pip install -r requirements.txt
9+
10+
CMD ["python", "main.py"]

examples/getting-started/app/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from flask import Flask, jsonify
2+
import os
3+
4+
app = Flask(__name__)
5+
pod_name = "unknown"
6+
pod_namespace = "unknown"
7+
cluster_id = os.environ.get("MEMBER_CLUSTER_ID", "unknown")
8+
9+
@app.route("/")
10+
def hello_world():
11+
return jsonify(
12+
message="Hello World!",
13+
pod_name=pod_name,
14+
pod_namespace=pod_namespace,
15+
cluster_id=cluster_id
16+
)
17+
18+
if __name__ == "__main__":
19+
try:
20+
with open("/etc/podinfo/name", "rt") as f:
21+
pod_name = f.read()
22+
with open("/etc/podinfo/namespace", "rt") as f:
23+
pod_namespace = f.read()
24+
except:
25+
pass
26+
27+
app.run(host="0.0.0.0", port=8080, debug=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask>=2.1.3
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: app
5+
namespace: work
6+
labels:
7+
app: hello-world
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: hello-world
13+
template:
14+
metadata:
15+
labels:
16+
app: hello-world
17+
spec:
18+
containers:
19+
- name: python
20+
image: $REGISTRY/app
21+
imagePullPolicy: Always
22+
ports:
23+
- containerPort: 8080
24+
env:
25+
- name: MEMBER_CLUSTER_ID
26+
valueFrom:
27+
configMapKeyRef:
28+
name: member-cluster-id
29+
key: id
30+
resources:
31+
requests:
32+
cpu: "0.2"
33+
memory: "400M"
34+
limits:
35+
cpu: "0.2"
36+
memory: "400M"
37+
volumeMounts:
38+
- mountPath: /etc/podinfo
39+
name: podinfo
40+
volumes:
41+
- name: podinfo
42+
downwardAPI:
43+
items:
44+
- path: "name"
45+
fieldRef:
46+
fieldPath: metadata.name
47+
- path: "namespace"
48+
fieldRef:
49+
fieldPath: metadata.namespace
50+
---
51+
apiVersion: v1
52+
kind: Service
53+
metadata:
54+
name: app
55+
namespace: work
56+
spec:
57+
type: LoadBalancer
58+
selector:
59+
app: hello-world
60+
ports:
61+
- port: 80
62+
targetPort: 8080
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: fleet-networking-controller
5+
namespace: fleet-member-[YOUR-MEMBER-CLUSTER-1]
6+
rules:
7+
- apiGroups:
8+
- coordination.k8s.io
9+
resources:
10+
- leases
11+
verbs:
12+
- create
13+
- get
14+
- list
15+
- update
16+
- apiGroups:
17+
- ""
18+
resources:
19+
- events
20+
verbs:
21+
- create
22+
- get
23+
- list
24+
- update
25+
- watch
26+
- patch
27+
- apiGroups:
28+
- networking.fleet.azure.com
29+
resources: ["*"]
30+
verbs: ["*"]
31+
---
32+
kind: RoleBinding
33+
apiVersion: rbac.authorization.k8s.io/v1
34+
metadata:
35+
name: fleet-networking-controller
36+
namespace: fleet-member-[YOUR-MEMBER-CLUSTER-1]
37+
roleRef:
38+
apiGroup: rbac.authorization.k8s.io
39+
kind: Role
40+
name: fleet-networking-controller
41+
subjects:
42+
- kind: User
43+
name: [YOUR-MEMBER-CLUSTER-1-PRINCIPAL-ID]
44+
---
45+
apiVersion: rbac.authorization.k8s.io/v1
46+
kind: Role
47+
metadata:
48+
name: fleet-networking-controller
49+
namespace: fleet-member-[YOUR-MEMBER-CLUSTER-2]
50+
rules:
51+
- apiGroups:
52+
- coordination.k8s.io
53+
resources:
54+
- leases
55+
verbs:
56+
- create
57+
- get
58+
- list
59+
- update
60+
- apiGroups:
61+
- ""
62+
resources:
63+
- events
64+
verbs:
65+
- create
66+
- get
67+
- list
68+
- update
69+
- watch
70+
- patch
71+
- apiGroups:
72+
- networking.fleet.azure.com
73+
resources: ["*"]
74+
verbs: ["*"]
75+
---
76+
kind: RoleBinding
77+
apiVersion: rbac.authorization.k8s.io/v1
78+
metadata:
79+
name: fleet-networking-controller
80+
namespace: fleet-member-[YOUR-MEMBER-CLUSTER-2]
81+
roleRef:
82+
apiGroup: rbac.authorization.k8s.io
83+
kind: Role
84+
name: fleet-networking-controller
85+
subjects:
86+
- kind: User
87+
name: [YOUR-MEMBER-CLUSTER-2-PRINCIPAL-ID]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: networking.fleet.azure.com/v1alpha1
2+
kind: MultiClusterService
3+
metadata:
4+
name: app
5+
namespace: work
6+
spec:
7+
serviceImport:
8+
name: app
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: networking.fleet.azure.com/v1alpha1
2+
kind: ServiceExport
3+
metadata:
4+
name: app
5+
namespace: work

examples/getting-started/bootstrap.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
if [ -z ${SUBSCRIPTION_ID+x} ]; then
2+
echo "Subscription ID is not set; to use the script, set the SUBSCRIPTION_ID variable."
3+
exit 1
4+
fi
5+
6+
if [ -z ${RESOURCE_GROUP+x} ]; then
7+
echo "Resource group is not set; to use the script, set the RESOURCE_GROUP variable."
8+
exit 1
9+
fi
10+
11+
if [ -z ${LOCATION+x} ]; then
12+
echo "Location is not set; to use the script, set the LOCATION variable."
13+
exit 1
14+
fi
15+
16+
if [ -z ${REGISTRY+x} ]; then
17+
echo "Registry is not set; to use the script, set the REGISTRY variable."
18+
exit 1
19+
fi
20+
21+
if [[ $REGISTRY == *.azurecr.io ]]; then
22+
echo "Registry is set with the full URL; to use the script, update the REGISTRY variable to use the registry name only."
23+
exit 1
24+
fi
25+
26+
echo "Creating the resource group..."
27+
az group create --name $RESOURCE_GROUP --location $LOCATION
28+
29+
echo "Creating the virtual network..."
30+
export VNET=fleet
31+
export HUB_SUBNET=hub
32+
export MEMBER_1_SUBNET=member-1
33+
export MEMBER_2_SUBNET=member-2
34+
35+
az network vnet create \
36+
--name $VNET \
37+
-g $RESOURCE_GROUP \
38+
--address-prefixes 10.0.0.0/8
39+
az network vnet subnet create \
40+
--vnet-name $VNET \
41+
--name $HUB_SUBNET \
42+
-g $RESOURCE_GROUP \
43+
--address-prefixes 10.1.0.0/16
44+
az network vnet subnet create \
45+
--vnet-name $VNET \
46+
--name $MEMBER_1_SUBNET \
47+
-g $RESOURCE_GROUP \
48+
--address-prefixes 10.2.0.0/16
49+
az network vnet subnet create \
50+
--vnet-name $VNET \
51+
--name $MEMBER_2_SUBNET \
52+
-g $RESOURCE_GROUP \
53+
--address-prefixes 10.3.0.0/16
54+
55+
echo "Creating the container registry..."
56+
az acr create -g $RESOURCE_GROUP -n $REGISTRY --sku basic
57+
sleep 10
58+
az acr login -n $REGISTRY
59+
60+
echo "Creating the hub cluster..."
61+
export NODE_COUNT=2
62+
export HUB_CLUSTER=hub
63+
az aks create \
64+
--location $LOCATION \
65+
--resource-group $RESOURCE_GROUP \
66+
--name $HUB_CLUSTER \
67+
--attach-acr $REGISTRY \
68+
--node-count $NODE_COUNT \
69+
--generate-ssh-keys \
70+
--enable-aad \
71+
--enable-azure-rbac \
72+
--network-plugin azure \
73+
--vnet-subnet-id "/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Network/virtualNetworks/$VNET/subnets/$HUB_SUBNET" \
74+
--yes
75+
76+
echo "Creating the first member cluster..."
77+
export MEMBER_CLUSTER_1=member-1
78+
az aks create \
79+
--location $LOCATION \
80+
--resource-group $RESOURCE_GROUP \
81+
--name $MEMBER_CLUSTER_1 \
82+
--attach-acr $REGISTRY \
83+
--node-count $NODE_COUNT \
84+
--generate-ssh-keys \
85+
--enable-aad \
86+
--enable-azure-rbac \
87+
--network-plugin azure \
88+
--vnet-subnet-id "/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Network/virtualNetworks/$VNET/subnets/$MEMBER_1_SUBNET" \
89+
--yes
90+
91+
echo "Creating the second member cluster..."
92+
export MEMBER_CLUSTER_2=member-2
93+
az aks create \
94+
--location $LOCATION \
95+
--resource-group $RESOURCE_GROUP \
96+
--name $MEMBER_CLUSTER_2 \
97+
--attach-acr $REGISTRY \
98+
--node-count $NODE_COUNT \
99+
--generate-ssh-keys \
100+
--enable-aad \
101+
--enable-azure-rbac \
102+
--network-plugin azure \
103+
--vnet-subnet-id "/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Network/virtualNetworks/$VNET/subnets/$MEMBER_2_SUBNET" \
104+
--yes
105+
106+
echo "Retrieving credentials for the Kubernetes clusters..."
107+
az aks get-credentials --name $HUB_CLUSTER -g $RESOURCE_GROUP --admin
108+
az aks get-credentials --name $MEMBER_CLUSTER_1 -g $RESOURCE_GROUP --admin
109+
az aks get-credentials --name $MEMBER_CLUSTER_2 -g $RESOURCE_GROUP --admin

0 commit comments

Comments
 (0)