springboot-web服务迁移Kubernetes

1、搞定基础镜像

docker pull openjdk:8-jre-alpine
docker tag openjdk:8-jre-alpine 10.204.82.15/kubernetes/openjdk:8-jre-alpine
docker push 10.204.82.15/kubernetes/openjdk:8-jre-alpine

 2、springboot-web应用服务打包

springboot-web服务迁移Kubernetes_第1张图片

3、编写Dockerfile构建镜像

FROM 10.204.82.15/kubernetes/openjdk:8-jre-alpine

COPY target/springboot-web-demo-1.0-SNAPSHOT.jar /springboot-web.jar

ENTRYPOINT ["java", "-jar", "/springboot-web.jar"]
docker build -t springboot-web:v1 .

docker tag springboot-web:v1 10.204.82.15/kubernetes/springboot-web:v1

4、编写springboot-web.yaml 

#deploy
apiVersion: apps/v1
kind: Deployment
metadata:
  name: springboot-web-demo
spec:
  selector:
    matchLabels:
      app: springboot-web-demo
  replicas: 1
  template:
    metadata:
      labels:
        app: springboot-web-demo
    spec:
      nodeSelector:
        app: ingress
      containers:
      - name: springboot-web-demo
        image: 10.204.82.15/kubernetes/springboot-web:v1
        ports:
        - containerPort: 8080
---
#service
apiVersion: v1
kind: Service
metadata:
  name: springboot-web-demo
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: springboot-web-demo
  type: ClusterIP

---
#ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: springboot-web-demo
spec:
  rules:
  - host: springboot.mooc.com
    http:
      paths:
      - path: /
        backend:
          serviceName: springboot-web-demo
          servicePort: 80

5、启动容器

kubectl apply -f springboot-web.yaml
 
kubectl get pods -o wide

你可能感兴趣的:(kubernetes,容器,云原生)