スポンサーリンク

skaffoldを使ってみる

kubernetes
この記事は約15分で読めます。

必要なもの

docker

kind

kubectl

 

$ docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:55:49 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:54:13 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


$ kind version
kind v0.11.1 go1.16.4 linux/amd64

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5", GitCommit:"aea7bbadd2fc0cd689de94a54e5b7b758869d691", GitTreeState:"clean", BuildDate:"2021-09-15T21:10:45Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

 

インストール

バイナリをダウンロードして使うだけ。

releaseから指定versionを取るのもわかりやすい

curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v1.34.0/skaffold-linux-amd64 && 
chmod +x skaffold && 
sudo mv skaffold /usr/local/bin

 

Installing Skaffold
Easy and Repeatable Kubernetes Development

 

GitHub - GoogleContainerTools/skaffold: Easy and Repeatable Kubernetes Development
Easy and Repeatable Kubernetes Development. Contribute to GoogleContainerTools/skaffold development by creating an account on GitHub.

 

quick start

こちらの通り動かしてみる

Quickstart
Easy and Repeatable Kubernetes Development

 

先にkindを起動させておく

kind create cluster


$ kubectl get pod -A
NAMESPACE            NAME                                         READY   STATUS    RESTARTS   AGE
kube-system          coredns-558bd4d5db-qxxjt                     1/1     Running   0          4m29s
kube-system          coredns-558bd4d5db-sz8q4                     1/1     Running   0          4m29s
kube-system          etcd-kind-control-plane                      1/1     Running   0          4m37s
kube-system          kindnet-rrj64                                1/1     Running   0          4m30s
kube-system          kube-apiserver-kind-control-plane            1/1     Running   0          4m37s
kube-system          kube-controller-manager-kind-control-plane   1/1     Running   0          4m37s
kube-system          kube-proxy-mwhlx                             1/1     Running   0          4m30s
kube-system          kube-scheduler-kind-control-plane            1/1     Running   0          4m37s
local-path-storage   local-path-provisioner-547f784dff-wl6wv      1/1     Running   0          4m29s

コード類をgit cloneして対象ディレクトリに移動しskaffold devと打つだけ。

コード類はここにある。

skaffold/examples/getting-started at v1.34.0 · GoogleContainerTools/skaffold
Easy and Repeatable Kubernetes Development. Contribute to GoogleContainerTools/skaffold development by creating an account on GitHub.

 

Ctrl + C打つまで[getting-started] Hello world!が表示される。

 

$ git clone --depth 1 https://github.com/GoogleContainerTools/skaffold
Cloning into 'skaffold'...
remote: Enumerating objects: 2511, done.
remote: Counting objects: 100% (2511/2511), done.
remote: Compressing objects: 100% (2005/2005), done.
remote: Total 2511 (delta 610), reused 1213 (delta 308), pack-reused 0
Receiving objects: 100% (2511/2511), 14.93 MiB | 17.82 MiB/s, done.
Resolving deltas: 100% (610/610), done.

$ cd skaffold/examples/getting-started

$ skaffold dev
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> skaffold-example:23f65f2
Checking cache...
 - skaffold-example: Not found. Building
Starting build...
Found [kind-kind] context, using local docker daemon.
Building [skaffold-example]...
Sending build context to Docker daemon  3.072kB
Step 1/8 : FROM golang:1.15 as builder
1.15: Pulling from library/golang
627b765e08d1: Pulling fs layer
c040670e5e55: Pulling fs layer
073a180f4992: Pulling fs layer
bf76209566d0: Pulling fs layer
6182a456504b: Pulling fs layer
73e3d3d88c3c: Pulling fs layer
5946d17734ce: Pulling fs layer
bf76209566d0: Waiting
6182a456504b: Waiting
73e3d3d88c3c: Waiting
5946d17734ce: Waiting
c040670e5e55: Verifying Checksum
c040670e5e55: Download complete
073a180f4992: Verifying Checksum
073a180f4992: Download complete
627b765e08d1: Verifying Checksum
627b765e08d1: Download complete
bf76209566d0: Verifying Checksum
bf76209566d0: Download complete
6182a456504b: Verifying Checksum
6182a456504b: Download complete
5946d17734ce: Verifying Checksum
5946d17734ce: Download complete
73e3d3d88c3c: Verifying Checksum
73e3d3d88c3c: Download complete
627b765e08d1: Pull complete
c040670e5e55: Pull complete
073a180f4992: Pull complete
bf76209566d0: Pull complete
6182a456504b: Pull complete
73e3d3d88c3c: Pull complete
5946d17734ce: Pull complete
Digest: sha256:ea080cc817b02a946461d42c02891bf750e3916c52f7ea8187bccde8f312b59f
Status: Downloaded newer image for golang:1.15
 ---> 40349a2425ef
Step 2/8 : COPY main.go .
 ---> 220a9515973a
Step 3/8 : ARG SKAFFOLD_GO_GCFLAGS
 ---> Running in b41a48c405d3
 ---> f30bb4c00077
Step 4/8 : RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /app main.go
 ---> Running in bca34b4c436b
 ---> 0edd03848770
Step 5/8 : FROM alpine:3
3: Pulling from library/alpine
a0d0a0d46f8b: Pulling fs layer
a0d0a0d46f8b: Verifying Checksum
a0d0a0d46f8b: Download complete
a0d0a0d46f8b: Pull complete
Digest: sha256:e1c082e3d3c45cccac829840a25941e679c25d438cc8412c2fa221cf1a824e6a
Status: Downloaded newer image for alpine:3
 ---> 14119a10abf4
Step 6/8 : ENV GOTRACEBACK=single
 ---> Running in 1f399b7e8014
 ---> f5be235f5e93
Step 7/8 : CMD ["./app"]
 ---> Running in 07bf297df19e
 ---> 1c77a859d9be
Step 8/8 : COPY --from=builder /app .
 ---> bdc437f5d5ba
Successfully built bdc437f5d5ba
Successfully tagged skaffold-example:23f65f2
Tags used in deployment:
 - skaffold-example -> skaffold-example:bdc437f5d5bacd64ec18e88cef8b47493451564a38b8c6e29aebd07919196a4f
Starting deploy...
Loading images into kind cluster nodes...
 - skaffold-example:bdc437f5d5bacd64ec18e88cef8b47493451564a38b8c6e29aebd07919196a4f -> Loaded
Images loaded in 1.119 second
 - pod/getting-started created
Waiting for deployments to stabilize...
 - pods is ready.
Deployments stabilized in 2.082 seconds
Press Ctrl+C to exit
Watching for changes...
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
^CCleaning up...
 - pod "getting-started" deleted

Help improve Skaffold with our 2-minute anonymous survey: run 'skaffold survey'

 

別窓建てて見てみる

skaffold dev中に確認。

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
skaffold-example 23f65f2 bdc437f5d5ba 32 minutes ago 7.63MB
skaffold-example bdc437f5d5bacd64ec18e88cef8b47493451564a38b8c6e29aebd07919196a4f bdc437f5d5ba 32 minutes ago 7.63MB

$ kubectl get pod
NAME              READY   STATUS    RESTARTS   AGE
getting-started   1/1     Running   0          7s

$ kubectl get deployments.apps 
No resources found in default namespace.

$ kubectl logs getting-started 
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!

※以下一部抜粋
$ kubectl get pod getting-started -o yaml
apiVersion: v1
kind: Pod
metadata:
spec:
  containers:
  - image: skaffold-example:bdc437f5d5bacd64ec18e88cef8b47493451564a38b8c6e29aebd07919196a4f
    imagePullPolicy: IfNotPresent
    name: getting-started

 

quickstartに流れは書いてある。

logの中に「Loading images into kind cluster nodes…」とあるから
kind load docker-imageもやってくれてそう。

・Dockerfileを使ってソースからDockerイメージを構築する
・Dockerイメージにそのコンテンツのsha256ハッシュをタグ付けする
・Kubernetesマニフェスト(k8s-pod.yaml)を更新して、先にビルドしたイメージを使用する。
・kubectl apply -fでKubernetesマニフェストをデプロイする。
・デプロイされたアプリからのログのストリーミング再生
スポンサーリンク
kubernetesskaffold
スポンサーリンク
hakenをフォローする
定年まで泣くんじゃない
タイトルとURLをコピーしました