Skip to content
Ajiyba Nesij edited this page Oct 9, 2019 · 3 revisions

Tensorflow Model Server converting Docker Image.

Installation of Docker

  • Docker installation can be accessed with this link.

1. Folder Structure

->Dockerfile
->models
    ->your_model_is_here
  • You can access this folder structure and files through this link.

2. Creation of Dockerfile for Tensorflow Model Server

  • The latest version of ubuntu is used for this docker image.

    • FROM ubuntu:latest
  • The necessary installations and commands to run are given to the "RUN" command as parameters.

    • RUN apt-get update && apt-get install -y \ build-essential \ curl \ libcurl3-dev \ git \ libfreetype6-dev \ libpng-dev \ libzmq3-dev \ pkg-config \ python-dev \ python-numpy \ python-pip \ software-properties-common \ swig \ zip \ zlib1g-dev
    • RUN apt-get install -y libstdc++6
    • RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
    • RUN apt-get -y upgrade
    • RUN apt-get -y dist-upgrade
    • RUN apt-get -y install python-pip
    • RUN pip install grpcio
    • RUN pip install tensorflow
    • RUN pip install tensorflow-serving-api
    • RUN echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | tee /etc/apt/sources.list.d/tensorflow-serving.list
    • RUN curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add -
    • RUN apt-get -y update && apt-get -y install tensorflow-model-server
  • The folder containing the model file is copied to the '/home' directory with the 'COPY' command.

    • COPY . /home
  • The 'CMD' command takes the first command to be executed at the terminal of the image as a parameter when the ubuntu image is executed.

    • CMD [ "tensorflow_model_server", "--rest_api_port=8501", "--model_name=MODEL_NAME", "--model_base_path=/home/models/MODEL_NAME"]
  • After the Dockerfile commands are prepared, the build operation must be done. This process may take a little longer.

    • docker build -t IMAGE_NAME .

3. Creation a New Container and Run

  • This command creates a new container from the created image.
    • docker run -p 8501:8501 IMAGE_NAME
  • The tensorflow model can be accessed with this address.
    • http://localhost:8501

Deploy The Tensorflow Model Image to Kubernetes

Installation of Docker

  • Docker installation can be accessed with this link.

1. Creation of deployment.yaml File

2. Deploy deployment.yaml File

  • This command is used to load deployment.yaml to the kubernetes cluster.
    kubectl apply –f deployment.yaml

3. Creation of service.yaml File

4. Deploy service.yaml File

  • This command is used to load service.yaml to the kubernetes cluster.
    kubectl apply –f service.yaml