1 使用dockerfile制作镜像

[root@master ~]# mkdir -p /opt/halo/files
[root@master ~]# cd /opt/halo/
[root@master halo]# touch Dockerfile
[root@master halo]# ls
Dockerfile  files

[root@master halo]#cat Dockerfiles
FROM openjdk:18-jdk-alpine
  
COPY files/halo-1.4.0.jar /usr/local/halo.jar

ENTRYPOINT ["java","-jar","/usr/local/halo.jar"]

[root@master halo]# docker build -t zhaojie10/halo:v1 .
[root@master halo]# docker images |grep halo
zhaojie10/halo      v1        cdf9f5edf641   24 seconds ago   407MB

[root@master halo]# docker login 
[root@master halo]# docker push zhaojie10/halo:v1 

2 定义资源文件

[root@master ~]# cd /opt/mainfest/
[root@master mainfest]# vi halo-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: halo
  labels:
    app: halo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: halo
  template:
    metadata:
      name: halo
      labels:
        app: halo
    spec:
      containers:
      - image: zhaojie10/halo:v1
        imagePullPolicy: IfNotPresent
        name: halo
---
apiVersion: v1
kind: Service
metadata:
  name: halo
spec:
  ports:
  - port: 8090
    targetPort: 8090
    nodePort: 30080
  selector:
    app: halo
  type: NodePort     

3 创建pod何service

[root@master mainfest]# kubectl apply -f halo-deploy.yaml 
deployment.apps/halo created
service/halo created
[root@master mainfest]# kubectl get pod,svc
NAME                        READY   STATUS    RESTARTS   AGE
pod/halo-3d7497763k-xm56k   1/1     Running   0          57s
pod/halo-3d7497763k-gh83f   1/1     Running   0          57s

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/halo         NodePort    10.100.143.169   <none>        8090:30080/TCP   13s
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          8d

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐