Skip to content

Commit

Permalink
Added example of kurator application feature on killercuda
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Jun 14, 2024
1 parent a477982 commit 364363a
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 0 deletions.
3 changes: 3 additions & 0 deletions application-example/finish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Summary

In this scenario, we learned how to use the kurator Application feature.
155 changes: 155 additions & 0 deletions application-example/foreground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# variable define
kind_version=v0.17.0
host_cluster_ip=172.30.1.2 #host node where Kurator is located
member_cluster_ip=172.30.2.2
local_ip=127.0.0.1
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}

function installKind() {
cat << EOF > installKind.sh
wget https://github.com/kubernetes-sigs/kind/releases/download/${kind_version}/kind-linux-amd64
chmod +x kind-linux-amd64
sudo mv kind-linux-amd64 /usr/local/bin/kind
EOF
}

function createCluster() {
cat << EOF > createCluster.sh
kind create cluster --name=member1 --config=cluster1.yaml
mv $HOME/.kube/config ~/config-member1
kind create cluster --name=member2 --config=cluster2.yaml
mv $HOME/.kube/config config-member2
KUBECONFIG=~/config-member1:~/config-member2 kubectl config view --merge --flatten >> ${KUBECONFIG_PATH}/config
# modify ip
sed -i "s/${local_ip}/${member_cluster_ip}/g" config-member1
scp config-member1 root@${host_cluster_ip}:$HOME/.kube/config-member1
sed -i "s/${local_ip}/${member_cluster_ip}/g" config-member2
scp config-member2 root@${host_cluster_ip}:$HOME/.kube/config-member2
EOF
}

function cluster1Config() {
touch cluster1.yaml
cat << EOF > cluster1.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "${member_cluster_ip}"
apiServerPort: 6443
EOF
}

function cluster2Config() {
touch cluster2.yaml
cat << EOF > cluster2.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "${member_cluster_ip}"
apiServerPort: 6444
EOF
}

function copyConfigFilesToNode() {
scp installKind.sh root@${member_cluster_ip}:~
scp createCluster.sh root@${member_cluster_ip}:~
scp cluster1.yaml root@${member_cluster_ip}:~
scp cluster2.yaml root@${member_cluster_ip}:~
}

function fluxcd_values() {
touch fluxcd.yaml
cat << EOF > fluxcd.yaml
imageAutomationController:
create: false
imageReflectionController:
create: false
notificationController:
create: false
EOF
}

function attachcluster() {
touch attachcluster.yaml
cat << EOF > attachcluster.yaml
apiVersion: cluster.kurator.dev/v1alpha1
kind: AttachedCluster
metadata:
name: kurator-member1
namespace: default
spec:
kubeconfig:
name: kurator-member1
key: kurator-member1.config
---
apiVersion: cluster.kurator.dev/v1alpha1
kind: AttachedCluster
metadata:
name: kurator-member2
namespace: default
spec:
kubeconfig:
name: kurator-member2
key: kurator-member2.config
EOF
}

function fleet() {
touch fleet.yaml
cat << EOF > fleet.yaml
apiVersion: fleet.kurator.dev/v1alpha1
kind: Fleet
metadata:
name: quickstart
namespace: default
spec:
clusters:
- name: kurator-member1
kind: AttachedCluster
- name: kurator-member2
kind: AttachedCluster
EOF
}

function install_kurator() {
# install Helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh
helm repo add jetstack https://charts.jetstack.io && helm repo update
kubectl create namespace cert-manager
helm install -n cert-manager cert-manager jetstack/cert-manager --set installCRDs=true
helm repo add fluxcd-community https://fluxcd-community.github.io/helm-charts
cat fluxcd.yaml | helm install fluxcd fluxcd-community/flux2 --version 2.7.0 -n fluxcd-system --create-namespace -f -
helm repo add kurator https://kurator-dev.github.io/helm-charts && helm repo update
# install kurator
helm install --create-namespace kurator-cluster-operator kurator/cluster-operator --version=0.6.0 -n kurator-system
helm install --create-namespace kurator-fleet-manager kurator/fleet-manager --version=0.6.0 -n kurator-system
}

kubectl delete node node01
kubectl taint node controlplane node-role.kubernetes.io/control-plane:NoSchedule-

# install kind and create member clusters
installKind
createCluster
cluster1Config
cluster2Config
fluxcd_values
copyConfigFilesToNode

install_kurator
attachcluster
fleet

# create cluster in node01 machine
ssh root@${member_cluster_ip} "bash ~/installKind.sh" &
sleep 10
ssh root@${member_cluster_ip} "bash ~/createCluster.sh"

# clean screen
clear
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions application-example/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"title": "Kurator Application",
"description": "Examples of Kurator Application",
"details": {
"intro": {
"text": "intro.md",
"foreground": "foreground.sh"
},
"steps": [
{
"title": "Prepare the execution environment for Application",
"text": "step1/text.md",
"verify": "step1/verify.sh"
},
{
"title": "Create Fleet",
"text": "step2/text.md",
"verify": "step2/verify.sh"
},
{
"title": "Run Kurator Application",
"text": "step3/text.md",
"verify": "step3/verify.sh"
}
],
"finish": {
"text": "finish.md"
}
},
"backend": {
"imageid": "kubernetes-kubeadm-2nodes"
}
}
7 changes: 7 additions & 0 deletions application-example/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Kurator Application

Kurator offers a unified system for distributing applications across multiple clusters, powered by Fleet.

By making use of the GitOps approach through FluxCD, Kurator automates the process of syncing and deploying applications. This makes the entire procedure quicker and more precise

Built to be flexible and responsive, Kurator’s distribution system is specially designed to accommodate various business and cluster demands.
49 changes: 49 additions & 0 deletions application-example/step1/text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Prerequisites

### AttachedCluster secrets

RUN `kubectl create secret generic kurator-member1 --from-file=kurator-member1.config=/root/.kube/config-member1`{{exec}}

RUN `kubectl create secret generic kurator-member2 --from-file=kurator-member2.config=/root/.kube/config-member2`{{exec}}

### Create attachedCluster resources

Now that we have the prerequisites sorted out, let’s move on to creating the AttachedCluster resources.

We’ll start by editing the configuration for the AttachedCluster.

Notice that the name and key here need to be consistent with the secret generated earlier.

We can apply the resources using the configuration provided below.

```console
apiVersion: cluster.kurator.dev/v1alpha1
kind: AttachedCluster
metadata:
name: kurator-member1
namespace: default
spec:
kubeconfig:
name: kurator-member1
key: kurator-member1.config
---
apiVersion: cluster.kurator.dev/v1alpha1
kind: AttachedCluster
metadata:
name: kurator-member2
namespace: default
spec:
kubeconfig:
name: kurator-member2
key: kurator-member2.config
```

RUN `kubectl apply -f attachcluster.yaml`{{exec}}

### View resource status

RUN `kubectl get attachedclusters.cluster.kurator.dev kurator-member1 -o yaml`{{exec}}

If the ready in status is true, the attachcluster was added successfully.

![Scan results](../image/attachcluster-success.png)
3 changes: 3 additions & 0 deletions application-example/step1/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

kubectl get attachedclusters.cluster.kurator.dev kurator-member1 -o yaml
26 changes: 26 additions & 0 deletions application-example/step2/text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Join with Fleet

To join the AttachedClusters into a fleet, create the yaml like this:

```console
cat <<EOF | kubectl apply -f -
apiVersion: fleet.kurator.dev/v1alpha1
kind: Fleet
metadata:
name: quickstart
namespace: default
spec:
clusters:
# add your AttachedCluster here
- name: kurator-member1
kind: AttachedCluster
- name: kurator-member2
kind: AttachedCluster
EOF
```

RUN `kubectl apply -f fleet.yaml`{{exec}}

## Check fleet status

RUN `kubectl get fleet -A`{{exec}}
3 changes: 3 additions & 0 deletions application-example/step2/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

kubectl get fleet -A
55 changes: 55 additions & 0 deletions application-example/step3/text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Kurator Application

Kurator offers a unified system for distributing applications across multiple clusters, powered by Fleet.

By making use of the GitOps approach through FluxCD, Kurator automates the process of syncing and deploying applications. This makes the entire procedure quicker and more precise

Built to be flexible and responsive, Kurator’s distribution system is specially designed to accommodate various business and cluster demands.

### Create an example application

Here is the content of example application resource. The YAML configuration of the example application outlines its source, synchronization policy, and other key settings. This includes the gitRepository as its source and two kustomization syncPolicies referring to a fleet that contains two attachedClusters

```console
echo 'apiVersion: apps.kurator.dev/v1alpha1
kind: Application
metadata:
name: gitrepo-kustomization-demo
namespace: default
spec:
source:
gitRepository:
interval: 3m0s
ref:
branch: master
timeout: 1m0s
url: https://github.com/stefanprodan/podinfo
syncPolicies:
- destination:
fleet: quickstart
kustomization:
interval: 5m0s
path: ./deploy/webapp
prune: true
timeout: 2m0s
- destination:
fleet: quickstart
kustomization:
targetNamespace: default
interval: 5m0s
path: ./kustomize
prune: true
timeout: 2m0s'| kubectl apply -f -
```

RUN `kubectl apply -f https://raw.githubusercontent.com/kurator-dev/kurator/main/examples/application/gitrepo-kustomization-demo.yaml`{{exec}}

### Check Application Status

RUN `kubectl describe application gitrepo-kustomization-demo`{{exec}}

Checking out pods in member clusters

RUN `kubectl get po -A --kubeconfig=/root/.kube/config-member1`{{exec}}

RUN `kubectl get po -A --kubeconfig=/root/.kube/config-member2`{{exec}}
3 changes: 3 additions & 0 deletions application-example/step3/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

kubectl get application -A

0 comments on commit 364363a

Please sign in to comment.