Java教程

K8s编排部署java应用

本文主要是介绍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
这篇关于K8s编排部署java应用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!