Have questions? Stuck? Please check our FAQ for some common questions and answers.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Architecture and codes


onos_install.sh
kubectl create -f install_clusterman.yml
kubectl create -f install_onos_config.yml
while true;
do
  sleep 2
  export IP1="$(kubectl get pods -o wide | grep sona-0 | gawk '{ print $6 }')"
  export IP2="$(kubectl get pods -o wide | grep sona-1 | gawk '{ print $6 }')"
  export IP3="$(kubectl get pods -o wide | grep sona-2 | gawk '{ print $6 }')"
  if [ "$IP1" != "" ] && [ "$IP2" != "" ] && [ "$IP3" != "" ] && [ "$IP1" != "<none>" ] && [ "$IP2" != "<none>" ] && [ "$IP3" != "<none>" ]
  then
    break;
  fi
  kubectl get pods -o wide
  echo "--------------------------------------------------------------------------------------"
done;
echo "cluster file has been created successfully ...... "
echo "waiting until all onos pods are running ..... "
while true;
do
  sleep 2
  export STATUS1="$(kubectl get pods -o wide | grep sona-0 | gawk '{ print $3 }')"
  export STATUS2="$(kubectl get pods -o wide | grep sona-1| gawk '{ print $3 }')"
  export STATUS3="$(kubectl get pods -o wide | grep sona-2| gawk '{ print $3 }')"
  if [ "$STATUS1" = "Running" ] && [ "$STATUS2" = "Running" ] && [ "$STATUS3" = "Running" ]
  then
    break;
  fi
  kubectl get pods -o wide
  echo "--------------------------------------------------------------------------------------"
done;
kubectl get pods -o wide
echo "Congratulations !!!! All onos pods are running with three node cluster.. hopefully... :-)"
install_onos.yml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: StatefulSet
metadata:
  name: onos-sona
spec:
  serviceName: "onos-sona"
  selector:
    matchLabels:
      app: sona-app
  replicas: 3
  template:
    metadata:
      labels:
        app: sona-app
    spec:
      initContainers:
        - name: noti-ip
          image: appropriate/curl
          command: ['sh', '-c','sleep 1; curl -X POST clusterman-service:9191/leave -d "{\"nodename\":\"$MY_POD_NAME\",\"nodeip\":\"\"}"; sleep 6; curl -X POST clusterman-service:9191/join -d "{\"nodename\":\"$MY_POD_NAME\",\"nodeip\":\"$MY_POD_IP\"}"']
          env:
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
      containers:
        - name: onos-app
          image: opensona/onos-sona-nightly-docker
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8101
            - containerPort: 8181
            - containerPort: 9876
            - containerPort: 6640
            - containerPort: 6653
          volumeMounts:
            - mountPath: /root/nginx-config
              name: nginx-config
          env:
            - name: JAVA_TOOL_OPTIONS
              value: "-Dfile.encoding=UTF8 -Donos.cluster.metadata.uri=http://clusterman-service:9191/cluster.json"
      volumes:
        - name: onos-config
          hostPath:
            path: /home/ubuntu/onos-config
            type: Directory
        - name: nginx-config
          hostPath:
            path: /tmp/nginx_conf
            type: Directory
---
apiVersion: v1
kind: Service
metadata:
  name: sona-service
spec:
  ports:
  - port: 8101
    name: karaf
  - port: 8181
    name: onos-rest
  - port: 9876
    name: cluster
  - port: 6640
    name: ovs
  - port: 6653
    name: openflow
  selector:
    app: sona-app
install_clusterman.yml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: clusterman-deployment
spec:
  selector:
    matchLabels:
      app: clusterman
  replicas: 1
  template:
    metadata:
      labels:
        app: clusterman
    spec:
      containers:
      - name: clusterman
        image: sangho/clusterman
        imagePullPolicy: Always
        ports:
        - containerPort: 9191
---
apiVersion: v1
kind: Service
metadata:
  name: clusterman-service
spec:
  ports:
  - port: 9191
    name: rest
  selector:
    app: clusterman


Cluster manager source code (golang)

download from https://github.com/sanghoshin/clustermanager.git

or visit https://github.com/sanghoshin/clustermanager

How it works

Auto Clustering Process

Auto Healing Process


Cluster manager API

POST clusterman-service:9191/leave

{
  "nodename":"NODE NAME", 
  "nodeip"  :""
}


POST clusterman-service:9191/join

{
  "nodename":"NODE NAME", 
  "nodeip"  :"10.1.1.1"
}


GET clusterman-service:9191/nodes

onos-sona-0:10.233.102.168
onos-sona-1:10.233.102.164
onos-sona-2:10.233.102.174


GET clusterman-service:9191/cluster.json

{"nodes": [{ "ip" : "10.233.102.168", "id": "onos-sona-0", "port" : 9876 }
,{ "ip" : "10.233.102.164", "id": "onos-sona-1", "port" : 9876 }
,{ "ip" : "10.233.102.174", "id": "onos-sona-2", "port" : 9876 }
],"name": 12345678, 
"partitions": [{"id": 1, "members": ["onos-sona-0","onos-sona-1","onos-sona-2"]}]}


Demo

  • No labels