K8s编排部署java应用

K8s编排部署java应用

[root@master ~]# cat test/Dockerfile 
FROM centos
LABEL MAINTAINER=haoran
ADD jdk-8u172-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.54.tar.gz  /usr/local/
ENV JAVA_HOME /usr/local/jdk1.8.0_172 
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.54
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.54
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
WORKDIR /usr/local/apache-tomcat-9.0.54
ENTRYPOINT /usr/local/apache-tomcat-9.0.54/bin/startup.sh && tail -f /usr/local/apache-tomcat-9.0.54/logs/catalina.out
CMD ["/usr/local/apache-tomcat-9.0.54/bin/catalina.sh","run"]

//构建镜像
[root@master ~]# docker build -t 133845005/java-deamon:v1 test

[root@master ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 133845005
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

[root@master ~]# docker push 1450146910/java-deamon:v1

[root@master test]# cat java.yaml 
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: java-deamon
  name: java
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: java-deamon
  template:
    metadata:
      labels:
        app: java-deamon
    spec:
      containers:
      - image: 133845005/java-deamon:v1
        name: java
        imagePullPolicy: IfNotPresent

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: java-deamon
  name: java
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    nodePort: 30000
    targetPort: 8080
  selector:
    app: java-deamon
  type: NodePort


[root@master test]# kubectl apply -f java.yaml 
deployment.apps/java created
service/java created

[root@master test]# kubectl get pod,svc
NAME                        READY   STATUS    RESTARTS   AGE
pod/java-53dscv5cs4-fsc15   1/1     Running   0          19s
pod/java-53dscv5cs4-36sc5   1/1     Running   0          19s

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/java         NodePort    10.18.65.34   <none>        80:30000/TCP   19s
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        9d
posted @ 2021-12-28 13:51  Aimmi  阅读(118)  评论(0编辑  收藏  举报