赞
踩
tags:
categories:
docker pull openjdk:8-jre-alpine
git clone https://gitee.com/qnhyn/mooc-k8s-demo-docker.git && cd /mooc-k8s-demo-docker/cronjob-demo
yum -y install java-1.8.0-openjdk maven
# 编译运行测试
mvn package && cd target
java -cp cronjob-demo-1.0-SNAPSHOT.jar com.mooc.demo.cronjob.Main
FROM openjdk:8-jre-alpine
COPY target/cronjob-demo-1.0-SNAPSHOT.jar /cronjob-demo.jar
ENTRYPOINT ["java", "-cp", "/cronjob-demo.jar", "com.mooc.demo.cronjob.Main"]
docker build -t cronjob:v1 .
# 运行镜像
docker run -it cronjob:v1
docker tag cronjob:v1 192.168.242.130/k8s/cronjob:v1
docker push 192.168.242.130/k8s/cronjob:v1
apiVersion: batch/v1beta1 kind: CronJob metadata: name: cronjob-demo spec: schedule: "*/1 * * * *" successfulJobsHistoryLimit: 3 suspend: false concurrencyPolicy: Forbid failedJobsHistoryLimit: 1 jobTemplate: spec: template: metadata: labels: app: cronjob-demo spec: restartPolicy: Never containers: - name: cronjob-demo image: 192.168.242.130/k8s/cronjob:v1
kubectl create -f cronjob.yaml
kubectl get cronjob
# 查看运行的执行机
kubectl get pods -o wide
# 查看结束容器
docker ps -a | grep cronjob
# 查看容器日志
docker logs 564f6f1796b4
cd springboot-web-demo
# 编译运行测试
mvn package && cd target
# 用jar 命令看jar打包的具体内容
jar -tf springboot-web-demo-1.0-SNAPSHOT.jar
# 运行服务
java -jar springboot-web-demo-1.0-SNAPSHOT.jar
# 访问服务
http://192.168.242.130:8080/hello?name=Michael
FROM 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 run -it springboot-web:v1
docker tag springboot-web:v1 192.168.242.130/k8s/springboot-web:v1
docker push 192.168.242.130/k8s/springboot-web:v1
# 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: containers: - name: springboot-web-demo image: 192.168.242.130/k8s/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: networking.k8s.io/v1beta1 kind: Ingress metadata: name: springboot-web-demo annotations: # use the shared ingress-nginx kubernetes.io/ingress.class: "nginx" spec: rules: - host: springboot.mooc.com http: paths: - path: / backend: serviceName: springboot-web-demo servicePort: 80
kubectl create -f springboot-web.yaml
# 查看运行的执行机
kubectl get pods -o wide
# 修改本机host 192.168.242.131 springboot.mooc.com
springboot.mooc.com/hello?name=Michael
# 首先启动一个docker容器挂载zookeeper,提供服务注册与发现 docker pull zookeeper:3.4.10 docker run --name zoo-server --restart always -p 2181:2181 -d zookeeper:3.4.10 # 修改zookeeper注册地址 容器所在ip用来解析 dubbo.registry.address=zookeeper://192.168.242.130:2181 cd dubbo-demo-api mvn install cd dubbo-demo mvn package # 查看具体内容 并解压 tar -tf dubbo-demo-1.0-SNAPSHOT-assembly.tar.gz tar -zvxf dubbo-demo-1.0-SNAPSHOT-assembly.tar.gz # 进入bin目录并启动 sh start.sh # 查看启动日志 cd logs && cat stdout.log # 查看项目是否启动 netstat -ntlp | grep 20880 telnet localhost 20880 # telnet下操作 调用函数 ls invoke com.mooc.demo.api.DemoService.sayHello("Dick") # 停止命令 sh stop.sh
mkdir ROOT
mv dubbo-demo-1.0-SNAPSHOT-assembly.tar.gz ROOT
tar -zvxf dubbo-demo-1.0-SNAPSHOT-assembly.tar.gz
rm -rf dubbo-demo-1.0-SNAPSHOT-assembly.tar.gz
FROM openjdk:8-jre-alpine
COPY target/ROOT /ROOT
ENTRYPOINT ["sh", "/ROOT/bin/start.sh"]
# 修改start.sh脚本 去掉nohup 让它不以后台方式运行和后面的重定向
# 删除下面检查进程的语句
PIDS=`ps --no-heading -C java -f --width 1000 | grep "${CONF_DIR}" |awk '{print $2}'`
if [ -n "${PIDS}" ]; then
echo "ERROR: The ${SERVER_NAME} already started!"
echo "PID: ${PIDS}"
exit 1
fi
cd target/ROOT/bin
docker build -t dubbo:v1 .
docker run -it dubbo:v1 .
docker tag dubbo:v1 192.168.242.130/k8s/dubbo:v1
docker push 192.168.242.130/k8s/dubbo:v1
if [ -z "${DUBBO_PORT}" ]; then
sed -i "s/dubbo.protocol.port=${SERVER_PORT}/dubbo.protocol.port=${DUBBO_PORT}/g" conf/dubbo.properties
SERVER_PORT=${DUBBO_PORT}
fi
# 重新生成镜像
docker build -t dubbo:v1 .
docker run -it dubbo:v1 .
docker tag dubbo:v1 192.168.242.130/k8s/dubbo:v1
docker push 192.168.242.130/k8s/dubbo:v1
#deploy apiVersion: apps/v1 kind: Deployment metadata: name: dubb-demo spec: selector: matchLabels: app: dubb-demo replicas: 1 template: metadata: labels: app: dubb-demo spec: hostNetwork: true affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: app operator: In values: - dubb-demo topologyKey: "kubernetes.io/hostname" containers: - name: dubb-demo image: 192.168.242.130/k8s/dubbo:v1 ports: - containerPort: 20881 # 这里通过环境变量 指定端口号 env: - name: DUBBO_PORT value: "20881"
netstat -ntlp | grep 20881
telnet localhost 20881
ls
invoke com.mooc.demo.api.DemoService.sayHello("Dick")
docker pull tomcat:8.0.51-alpine
docker tag tomcat:8.0.51-alpine 192.168.242.130/k8s/tomcat:8.0.51-alpine
docker push 192.168.242.130/k8s/tomcat:8.0.51-alpine
# /web-demo/src/main/resources/applicationContext-service-config.xml 修改zookeeper地址
mvn package
mkdir ROOT
mv web-demo-1.0-SNAPSHOT.war ROOT
jar -xvf web-demo-1.0-SNAPSHOT.war
rm -rf web-demo-1.0-SNAPSHOT.war
# 运行一个镜像 查看ROOT所在目录
docker run -it --entrypoint bash tomcat:8.0.51-alpine
FROM tomcat:8.0.51-alpine
COPY target/ROOT /usr/local/tomcat/webapps/ROOT
COPY dockerfiles/start.sh /usr/local/tomcat/bin/start.sh
ENTRYPOINT ["sh" , "/usr/local/tomcat/bin/start.sh"]
docker build -t web:v1 .
docker run -it web:v1 .
docker tag web:v1 192.168.242.130/k8s/web:v1
docker push 192.168.242.130/k8s/web:v1
# deploy apiVersion: apps/v1 kind: Deployment metadata: name: web-demo spec: selector: matchLabels: app: web-demo replicas: 1 template: metadata: labels: app: web-demo spec: containers: - name: web-demo image: 192.168.242.130/k8s/web:v1 ports: - containerPort: 8080 --- #service apiVersion: v1 kind: Service metadata: name: web-demo spec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: app: web-demo type: ClusterIP --- #ingress apiVersion: extensions/v1beta1 kind: Ingress metadata: name: web-demo spec: rules: - host: web.mooc.com http: paths: - path: / backend: serviceName: web-demo servicePort: 80
# 修改hosts文件
192.168.242.131 web.mooc.com
web.mooc.com/hello?name="小姐姐"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。