Publish the project to kubernetes using the Skaffold one click

Source: Internet
Author: User
Tags k8s

The current skaffold version is v0.4 and has not yet been released, and is not recommended for use in production environments;
Skaffold is used for developer rapid deployment programs to Kubernetes,Skaffold provides dev, run two modes , and Skaffold requires a skaffold configuration file that defines Skaffold workflow ;
The Skaffold workflow defines three main stages : Build, Push, Deploy;

First, Build
During the build phase, Skaffold uses the dockerfile to generate Artifacts,skaffold docker images, Bazel, in the current artifacts, which uses a Docker image so it can also be called a Docker image. , the image is used to run the application, and the output of the build phase is artifacts;
Second, Push
During the push phase, Skaffold will push the Docker image generated during the build phase to the Docker image repository and use the configured image name, ensuring that the image is pushed to the mirrored warehouse when the skaffold is run;
However, if you are using a minikube or Docker for desktop local kubernetes cluster, the default is not to push to the mirror warehouse, skip the push phase, because the local already exists the image so it can run normally;
Third, Deploy
Deployment phase, deploy the latest Docker image to k8s, which can use different deployment tools, such as Kubectl or helm, each with distinct parameters that define how to install and update the application;

Concept Introduction

Artifacts
In the build phase, by running a series of steps to create artifacts, artifacts into Bazel and Docker images in Skaffold, you can define skaffold to generate multiple Docker images, skaffold when running in development mode, Skaffold will only regenerate the Docker image where the source code has changed, generate the Docker image by specifying Dockerfile in the Skaffold configuration, and specify its name;

Label Policy
The tag policy is configured in the build phase to configure Skaffold to label the image when pushing the Docker image, currently skaffold supports three tag policies:sha256 tag generator, git tag generator, custom tag generator policy ;
In the development process, it is recommended to use the Content-based label policy sha256 to facilitate the skaffold of the kubernetes to redeploy the new Docker image when the source code changes;

Operating mode

Skaffold has Dev, run two operating modes, that is, the development mode and release mode, in the dev mode skaffold will monitor the project's source code with the changes in real-time re-production of the image and the change update to Kubernetes, but also in the ci/ Running Skaffold in the CD pipeline;

  The dev mode uses the sha256 tag generator by default
  run mode uses git tag builder by default

So note that if you use Run mode and do not configure git then Skaffold is unable to run down, you need to configure the tag policy (tagpolicy), or configure Git;

Use process:

The development environment uses the Skaffold deployment project to the remote k8s;
  1. Download Skaffold
Https://github.com/GoogleCloudPlatform/skaffold/releases/download/v0.4.0/skaffold-windows-amd64.exe
  2, download Kubectl, server open Docker remote connection
Add:-H tcp://0.0.0.0:2375 in the server-side Docker configuration
On the developer side, create the C:\Users\xin.docker\config.json file with the following content:

 {    "auths" : {    } }

  3. KUBECTL configuration of development terminal
Create the C:\Users\xin.kube\config.json file, configure the k8s connection and key, and the file contents are as follows:

 apiVersion: v1 clusters: - cluster:     server: http://182.61.xx.xxx:8001   name: minikube contexts: - context:     cluster: minikube     user: minikube   name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube   user: as-user-extra: {}

  4, the service end KUBECTL use to open the agent
Kubectl proxy--address 0.0.0.0--accept-hosts '. *
  5. Environment variable Configuration
You need to configure the link information for Docker in the environment variable:

 DOCKER_HOST = tcp://xxx.xxx.xxx.xxx:2375 DOCKER_TLS_VERIFY = 0

Download the demo and use Skaffold to deploy it to kubernetes;

git clone https://github.com/GoogleCloudPlatform/skaffold
CD examples/getting-started

Run: Skaffold Dev


You can see that because of the use of Minikube, only the build, deploy two stages skip the push phase, which is consistent with what we said above;
Modify the contents of the Main.go to see Skaffold detected changes, and re-update the project to Kubernetes;


  Common exception Information:

 WARN[0005] run: build: build step: running build: read auth configs: docker config: opening docker config:  open C:\Users\xin\.docker\config.json: no such file or directory   

The. Docker\confog.json file does not exist and can be added to the user directory;

 open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on  Windows, the docker client must be run elevated to connect. This error may also indicate that the docker  daemon is not running.  

DOCKER environment variables are not configured, plus docker_host, docker_tls_verify environment variables;

The environments used in this article are: Minikube, Skaffold v0.4, Windows

Article starting address: Solinx
http://www.solinx.co/archives/1163

Reference: HTTPS://GITHUB.COM/GOOGLECLOUDPLATFORM/SKAFFOLD/BLOB/MASTER/DOCS/CONCEPTS.MD

Publish the project to kubernetes using the Skaffold one click

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.