简体   繁体   中英

Deploying Docker image to Kubernetes

I have been working with Docker the last days and I have created a basic Docker image with a Dockerfile. It just starts a web server. Now, I have been reading further and created an account at Google Application Engine and want to deploy this image to Kubernetes.

I feel lost.

I don't understand how my Dockerfiles that I have locally is ment to be transferred to this platform? Don't I use them at all? I have seen some examples of Pod configuration but as far I can see they refer to images at Docker Hub?

Could someone point me in the right direction on what to do?

I have not worked with Kubernetes, but as far as I know, I think you have to upload to containers to a docker image repository. You can use the official hub and upload your images there (public images are free to upload, and you can have one private for free or pay for more). Also you can have a private docker image repository, and configure kubernetes to use it.

As I understand from this post , you can run link a Google Cloud bucket with a docker repository running locally, then configure a kubernetes pod to point to that bucket, and all the rest of your pods can consume docker images from there.

First of All I am somewhat lost on this myself, though was able to make a basic working sample of a php script running in a docker image on a Google Cloud Engine vm instance inside a Container Engine cluster. Where the docs states more simply

A Container Engine cluster is a group of Compute Engine instances running Kubernetes...

So In ANSWER to the question

Please see the following GitHub repository https://github.com/CrandellWS/Kubernetes-Php-Example

There is minimal files and source. You will find the Dockerfile in the root and a single php page in the src folder.

An automated build was setup for this via docker and can be found at https://registry.hub.docker.com/u/crandellws/kubernetes-php-example/

Replicating this would be done by forking the GitHub repository and setting up your Automated Build see: http://docs.docker.com/docker-hub/builds/

Once this is done you can then pull the docker image into a Kubernetes setup and run it. Such as the following shows with the mentioned Dockerfile:

sudo docker pull crandellws/kubernetes-php-example
sudo docker run -p 80:80 -it -d --name csupport crandellws/kubernetes-php-example

https://cloud.google.com/container-engine/docs/

To pull image from a private repository on GKE we need to create a secret of type docker-registry for authentication.

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

Include the imagePullSecrets tag in your yaml file as below and you will be able to pull image from mentioned repository.

apiVersion: v1
kind: Pod
metadata:
    name: pull-demo
spec:
    containers:
    - name: pull-demo-container
      image: nginx
    imagePullSecrets:
    - name: regsecret  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM