在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

你可能感兴趣的:(在K8s上部署一个简单的springboot项目)