Code Monkey home page Code Monkey logo

shifu_demo's Introduction

Shifu_demo

在Kubernetes中运行Shifu并编写一个应用的实践过程

部署并运行 Shifu

sudo docker ps

image-20240425113905126

Shifu 安装已完成

sudo kubectl get pods -A

image-20240425114934734

运行一个酶标仪的数字孪生

准备

image-20240425115503308

运行

sudo kubectl apply -f run_dir/shifu/demo_device/edgedevice-plate-reader

image-20240425115552852

sudo kubectl get pods -A | grep plate

成功启动

image-20240425115613590

交互

进入 nginx

image-20240425115757817

curl "deviceshifu-plate-reader.deviceshifu.svc.cluster.local/get_measurement"

image-20240425115907998

编写一个 Go 程序

编写代码

package main

import (
	"io/ioutil"
	"log"
	"net/http"
	"time"
)

func main() {
	targetUrl := "http://deviceshifu-plate-reader.deviceshifu.svc.cluster.local/get_measurement"
	req, _ := http.NewRequest("GET", targetUrl, nil)
	for {
		res, _ := http.DefaultClient.Do(req)
		body, _ := ioutil.ReadAll(res.Body)
		average := calculateAverage(body)
		log.Println("Average:", average)
		time.Sleep(2 * time.Second)
	}
}

func calculateAverage(data []byte) float64 {
	sum := 0
	count := 0
	for _, value := range data {
		sum += int(value)
		count++
	}
	if count > 0 {
		return float64(sum) / float64(count)
	}
	return 0
}

docker 打包

image-20240425161303225

将应用镜像加载到 kind

image-20240425161347384

运行容器 Pod

image-20240425161445390

成功运行

image-20240425162057630

检查应用输出

每两秒打印一次切片的值,符合程序预期

image-20240425161838534

shifu_demo's People

Contributors

violapioggia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.