k8s: start using grpc health check for cartservice (#63)

This commit is contained in:
Ahmet Alp Balkan 2018-10-01 23:20:42 -07:00 committed by GitHub
parent 848d4bbe90
commit 2771a03727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 9 additions and 2701 deletions

View file

@ -45,12 +45,12 @@ spec:
readinessProbe:
initialDelaySeconds: 15
exec:
command: ["/cartservice_probe"]
command: ["/bin/grpc_health_probe", "-addr=:7070"]
livenessProbe:
initialDelaySeconds: 15
periodSeconds: 10
exec:
command: ["/cartservice_probe"]
command: ["/bin/grpc_health_probe", "-addr=:7070"]
---
apiVersion: v1
kind: Service

View file

@ -38,7 +38,7 @@ spec:
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/"
path: "/_healthz"
port: 8080
httpHeaders:
- name: "Cookie"

View file

@ -1,13 +1,3 @@
FROM golang:1.10 as probe
RUN wget -qO/go/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && \
chmod +x /go/bin/dep
ENV PROJECT github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe
WORKDIR /go/src/$PROJECT
COPY probe/Gopkg.* ./
RUN dep ensure --vendor-only -v
COPY ./probe ./
RUN go build -o /cartservice_probe .
FROM microsoft/dotnet:2.1-sdk-alpine as builder
WORKDIR /app
COPY . .
@ -17,8 +7,11 @@ RUN dotnet restore && \
# cartservice
FROM alpine:3.8
# Add the probe
COPY --from=probe /cartservice_probe /cartservice_probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
# Dependencies for runtime
# busybox-extras => telnet
RUN apk add --no-cache \
@ -32,4 +25,4 @@ RUN apk add --no-cache \
icu
WORKDIR /app
COPY --from=builder /cartservice .
ENTRYPOINT ["./cartservice", "start"]
ENTRYPOINT ["./cartservice", "start"]

View file

@ -1 +0,0 @@
vendor/

View file

@ -1,101 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/timestamp"
]
revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265"
version = "v1.1.0"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"trace"
]
revision = "f4c29de78a2a91c00474a2e689954305c350adf9"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "0ffbfd41fbef8ffcf9b62b0b0aa3a5873ed7a4fe"
[[projects]]
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
]
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
branch = "master"
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "daca94659cb50e9f37c1b834680f2e46358f10b0"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"codes",
"connectivity",
"credentials",
"encoding",
"encoding/proto",
"grpclog",
"internal",
"internal/backoff",
"internal/channelz",
"internal/envconfig",
"internal/grpcrand",
"internal/transport",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"stats",
"status",
"tap"
]
revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
version = "v1.14.0"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "8f3c07df5ebc7dc4d50ca8a6c274eef95f3045d33bbe5f384271fa87166a457e"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -1,42 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "github.com/golang/protobuf"
version = "1.1.0"
[[constraint]]
branch = "master"
name = "golang.org/x/net"
[[constraint]]
name = "google.golang.org/grpc"
version = "1.14.0"
[prune]
go-tests = true
unused-packages = true

View file

@ -1,4 +0,0 @@
# cartservice Probe
This probe makes a call to the cartservice over localhost and exits to verify
liveness of the cartservice.

View file

@ -1,22 +0,0 @@
#!/bin/bash -eu
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#!/bin/bash -e
PATH=$PATH:$GOPATH/bin
protodir=../../../pb
protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto

File diff suppressed because it is too large Load diff

View file

@ -1,51 +0,0 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"log"
"os"
"time"
pb "github.com/GoogleCloudPlatform/microservices-demo/src/cartservice/probe/genproto"
"google.golang.org/grpc"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
log.Fatal("probe is executed without PORT env var")
}
log.Printf("probe executing on port %q", port)
conn, err := grpc.DialContext(context.TODO(),
"127.0.0.1:"+port,
grpc.WithBlock(),
grpc.WithTimeout(time.Second*3),
grpc.WithInsecure(),
)
if err != nil {
log.Fatalf("probe failed: failed to connect: %+v", err)
}
defer conn.Close()
if _, err := pb.NewCartServiceClient(conn).GetCart(context.TODO(),
&pb.GetCartRequest{UserId: "exec-probe-nonexistinguser"}); err != nil {
log.Fatalf("probe failed: failed to query: %+v", err)
}
log.Println("probe successful")
}