本篇主要介紹Docker映象的製作、RC和Service的建立。

Docker映象製作   下面以segment微服務為例描述Docker映象製作過程。 微服務配置檔案config.properties內容:

#restful API config listen.ip=0.0.0.0 listen.port=8081

#mirco server config mircoServer.name=segment jar.path=file:segment-1.0.jar jar.actionClass=com.robin.segment.action.SegmentAction

#log config log.path=log/ log.prefix=segment # Level.ALL Level.FINEST Level.FINER Level.FINE Level.CONFIG  # Level.INFO Level.WARNING Level.SEVERE Level.OFF log.level=Level.INFO log.file.limit=1048576 log.file.count=3

#robin segment dictinary config dic.base=dic/RS/base.dic dic.numeral=dic/RS/numeral.dic dic.quantifier=dic/RS/quantifier.dic dic.encoding=UTF-8

#paoding config paoding.analysis.properties=lib/paoding/paoding-analysis.properties 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Dockerfile檔案:

From hub.c.163.com/public/ubuntu:14.04-common MAINTAINER robin [email protected]

ADD jdk-8u162-linux-x64.tar.gz /usr/bin/ ENV JAVA_HOME /usr/bin/jdk1.8.0_162 ENV CLASSPATH ${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib ENV PATH ${JAVA_HOME}/bin:$PATH ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata

COPY JerseyServer /opt/JerseyServer/ 1 2 3 4 5 6 7 8 9 10 11 12 映象製作shell指令碼:

#!/bin/bash

RUN_PATH=$(readlink -f .)

INSTALL_DIR=JerseyServer CONFIG_FILE=$RUN_PATH/../config.properties LIB_DIR=$RUN_PATH/../lib START_DATA=$RUN_PATH/../dic START_SCRIPT=startup.sh

JERSEY_SERVER_JAR_PATH=../../JerseyServer/target/JerseyServer-1.0.jar MICRO_SERVICE_JAR_PATH=$RUN_PATH/../dist/segment-1.0.jar IMAGE_TAR_NAME=ubuntu-segment-0.1.tar IMAGE_TAG=docker.robin.com/robin/ubuntu-segment:0.1

echo "----------------Prepare project--------------------------------------" rm -fr $INSTALL_DIR mkdir -p $INSTALL_DIR cp $JERSEY_SERVER_JAR_PATH $INSTALL_DIR cp $CONFIG_FILE $MICRO_SERVICE_JAR_PATH $INSTALL_DIR cp -r $LIB_DIR $INSTALL_DIR cp -r $START_DATA $INSTALL_DIR cp $START_SCRIPT $INSTALL_DIR

echo "----------------Clean images ----------------------------------------" rm -fr $IMAGE_TAR_NAME docker rmi $IMAGE_TAG

echo "----------------Build images ----------------------------------------" docker build -t $IMAGE_TAG .

echo "----------------Save images: ${IMAGE_TAR_NAME}----------------------------" docker save $IMAGE_TAG > $IMAGE_TAR_NAME

echo "----------------Copy images: ${IMAGE_TAR_NAME}----------------------------" NODE2_ADDRESS=192.168.1.12 NODE3_ADDRESS=192.168.1.13 NODE4_ADDRESS=192.168.1.14

scp $IMAGE_TAR_NAME $NODE2_ADDRESS:/home/dockerImg ssh [email protected]$NODE2_ADDRESS "docker rmi $IMAGE_TAG" ssh [email protected]$NODE2_ADDRESS "cd /home/dockerImg; docker load --input $IMAGE_TAR_NAME"

scp $IMAGE_TAR_NAME $NODE3_ADDRESS:/home/dockerImg ssh [email protected]$NODE3_ADDRESS "docker rmi $IMAGE_TAG" ssh [email protected]$NODE3_ADDRESS "cd /home/dockerImg; docker load --input $IMAGE_TAR_NAME"

scp $IMAGE_TAR_NAME $NODE4_ADDRESS:/home/dockerImg ssh [email protected]$NODE4_ADDRESS "docker rmi $IMAGE_TAG" ssh [email protected]$NODE4_ADDRESS "cd /home/dockerImg; docker load --input $IMAGE_TAR_NAME" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 本地映象檢視:

[[email protected] home]# docker images REPOSITORY                                     TAG                 IMAGE ID            CREATED             SIZE docker.robin.com/robin/ubuntu-pretreatment     0.1                 7da0704a794b        22 hours ago        761.3 MB docker.robin.com/robin/ubuntu-classifier       0.1                 4b39c146e6c0        4 days ago          761.6 MB docker.robin.com/robin/ubuntu-feature-select   0.1                 4d6ca3e5e6db        4 days ago          761.4 MB docker.robin.com/robin/ubuntu-segment          0.1                 49285ef474f3        4 days ago          774.7 MB gcr.io/google_containers/pause-amd64           3.0                 99e59f495ffa        2 years ago         746.9 kB hub.c.163.com/public/ubuntu                    14.04-common        493d50b6de79        2 years ago         369.3 MB 1 2 3 4 5 6 7 8 Docker映象私倉映象查詢:

[[email protected] home]# curl http://docker.robin.com/v2/_catalog {"repositories":["robin/ubuntu-classifier","robin/ubuntu-feature-select","robin/ubuntu-pretreatment","robin/ubuntu-segment"]} 1 2 K8S RC建立   下面以classifier微服務為例描述RC的建立。 classifier-rc.yaml配置:

apiVersion: v1 kind: ReplicationController metadata:   name: classifier-rc spec:   replicas: 4   selector:     app: ubuntu-classifier   template:     metadata:       labels:         app: ubuntu-classifier     spec:       containers:       - name: ubuntu-classifier         image: docker.robin.com/robin/ubuntu-classifier:0.1         command: ["/bin/sh", "-c"]         args: ["cd /opt/JerseyServer;./startup.sh"]         resources:           limits:             cpu: 1500m             memory: 1280Mi           requests:             cpu: 1000m             memory: 1024Mi       imagePullSecrets:         - name: robin-registrykey 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 建立RC:

kubectl create -f classifier-rc.yaml 1 查詢RC:

[[email protected] yaml]# kubectl get rc NAME                DESIRED   CURRENT   READY     AGE classifier-rc       4         4         4         4d feature-select-rc   1         1         1         4d pretreatment-rc     1         1         1         22h segment-rc          1         1         1         4d 1 2 3 4 5 6 查詢endpoints

[[email protected] yaml]# kubectl get endpoints NAME                 ENDPOINTS                                               AGE classifier-svc       10.0.1.2:8084,10.0.7.2:8084,10.0.8.2:8084 + 1 more...   4d feature-select-svc   10.0.1.3:8083                                           4d kubernetes           192.168.1.10:6443                                       172d pretreatment-svc     10.0.7.4:8082                                           22h segment-svc          10.0.7.3:8081                                           4d 1 2 3 4 5 6 7 K8S Service建立 Classifier Service配置:

apiVersion: v1 kind: Service metadata:   name: classifier-svc spec:   type: NodePort   ports:   - port: 8004     targetPort: 8084     nodePort: 30084   selector:     app: ubuntu-classifier 1 2 3 4 5 6 7 8 9 10 11 12 Service建立:

kubectl create -f classifier-svc.yam 1 Service查詢:

---------------------  作者:xsdjj  來源:CSDN  原文:https://blog.csdn.net/xsdjj/article/details/83927975  版權宣告:本文為博主原創文章,轉載請附上博文連結!