k8s CI/CD利器skaffold初试

关于asaffold是个什么玩意以及安装,请自行百度;详细用法:https://skaffold.dev/docs/。
这里用一个简单的go程序做测试其功能,主要的文件如下:
main.go

package main

import (
    "io"
    "net/http"
)
func main() {
    http.HandleFunc("/", helloWorldHandler)
    http.ListenAndServe(":8800", nil)
}
func helloWorldHandler(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "Hello world! ,and from akaffold v1")
}

app.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: skaffold-test
spec:
   replicas: 1
   template:
     metadata:
       labels:
         name: skaffold-test
     spec:
       containers:
         - name: skaffold-test
           image: 172.21.205.57:5005/akaffold/test  #会自动引用下面的image tag版本
           ports:
             - containerPort: 8800
---
apiVersion: v1
kind: Service
metadata:
  name: skaffold-test-service
spec:
  ports:
    - port: 8800
      targetPort: 8800
      protocol: TCP
  selector:
    name: skaffold-test

Dockerfile

FROM 172.21.205.57:5005/golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

FROM 172.21.205.57:5005/alpine:3.7  
CMD ["./app"]
COPY --from=builder /app .

skaffold.yaml

apiVersion: skaffold/v1beta3
kind: Config
build:    # build部分与deploy部分是独立的,可以随意组合
  artifacts:
    - image: 172.21.205.57:5005/akaffold/test
  tagPolicy:
    dateTime:   #image tag 
      format: "2006-01-02-15-04-05"
      timezone: "Local" 
  local:
    push: true
deploy:
  kubectl:
    manifests:
      - app.yaml
    flags:
      apply:
        - --force=true
        - --grace-period=0

开始测试

skaffold run
k8s CI/CD利器skaffold初试_第1张图片
image.png

通过nginx访问
[图片上传中...(image.png-f91f4c-1552897853420-0)]
更改main.go文件,将v1改为v2

skaffold run

再次通过nginx访问


image.png

顺利实现想象中的逻辑,skaffold的强大功能远不如此,值得深入研究;然后我越来越觉着这货的逻辑很像一个工具:circleci.

你可能感兴趣的:(k8s CI/CD利器skaffold初试)