在K8s上部署一个简单的springboot项目

svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: helloworld
  labels:
    app: helloworld
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30080
    protocol: TCP
    name: web
  selector:
    app: helloworld

deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
  labels:
    app: helloworld
spec:
  replicas: 3
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: liyongweicn/helloworld_springboot:v2
        ports:
        - containerPort: 8080

运行

kubectl apply -f svc.yaml
kubectl apply -f deploy.yaml

然后访问<节点的IP>:30080/hello即可。
通过查看Pod的log可以看到,每次访问通过轮询的方式实现了负载均衡。

kubectl logs helloworld-deployment-548748dcc5-98jn9
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容