第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在GKE中使用HTTPS部署Echo應(yīng)用程序?

如何在GKE中使用HTTPS部署Echo應(yīng)用程序?

Go
手掌心 2022-08-15 16:55:28
如何在GKE中使用HTTPS部署Echo應(yīng)用程序?使用Echo框架開(kāi)發(fā)了一個(gè)Web應(yīng)用程序。使用其自動(dòng) TLS 設(shè)置功能。https://<DOMAIN>package mainimport (    "net/http"    "github.com/labstack/echo/v4"    "github.com/labstack/echo/v4/middleware"    "golang.org/x/crypto/acme/autocert")func main() {    e := echo.New()    env := os.Getenv("ENV")    if env == "prod" {        e.AutoTLSManager.HostPolicy = autocert.HostWhitelist("arealdomain.com")        e.AutoTLSManager.Cache = autocert.DirCache("/var/www/cert")        e.Pre(middleware.HTTPSWWWRedirect())    }    e.GET("/healthcheck", func(c echo.Context) error {        return c.JSON(http.StatusOK, {"ok"})    })    switch env {    case "prod":        e.Logger.Fatal(e.StartAutoTLS(":8443"))    case "dev":        e.Logger.Fatal(e.Start(":9000"))    default:        e.Logger.Fatal(e.Start(":9000"))    }}在 Kubernetes 中部署了它。開(kāi)發(fā).ymlapiVersion: apps/v1kind: Deploymentmetadata:  name: testappspec:  selector:    matchLabels:      app: testapp  replicas: 3  template:    metadata:      labels:        app: testapp    spec:      containers:        - name: testapp          image: gcr.io/<PROJECT_ID>/testapp      ports:      - containerPort: 9000      - containerPort: 8443      livenessProbe:        initialDelaySeconds: 10        periodSeconds: 10        exec:          command:            - "true"      readinessProbe:        initialDelaySeconds: 5        periodSeconds: 20        httpGet:          path: /healthcheck          port: 9000服務(wù).ymlapiVersion: v1kind: Servicemetadata:  name: testappspec:  type: NodePort  ports:  - name: http    protocol: TCP    port: 80    targetPort: 9000  selector:    app: testappingress.ymlapiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:  name: testingress  annotations:    kubernetes.io/ingress.global-static-ip-name: testip // a real IP    networking.gke.io/managed-certificates: testcertificate    kubernetes.io/ingress.class: "gce"spec:  backend:    serviceName: testapp    servicePort: 80managedcertificate.yml
查看完整描述

1 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果您剛剛開(kāi)始使用 GKE,我建議您只創(chuàng)建服務(wù)和部署,并使用 UI 創(chuàng)建入口和托管證書(shū)


我創(chuàng)建并部署了一個(gè)示例應(yīng)用程序:


main.go 中的代碼


package main


import (

    "log"

    "net/http"

)


func main() {

    // change this handlers for echo handlers

    http.HandleFunc("/", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {

        rw.WriteHeader(http.StatusOK)

        rw.Write([]byte("Hello World..."))

    }))

    http.HandleFunc("/health", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {

        rw.WriteHeader(http.StatusOK)

    }))

    log.Panic(http.ListenAndServe(":8080", nil))

}


Dockerfile


FROM golang:alpine AS builder

RUN apk add --no-cache git

WORKDIR /go/src/app

COPY . .

RUN go build -o bin main.go


#final stage

FROM alpine:latest

RUN apk --no-cache add ca-certificates

COPY --from=builder /go/src/app/bin /app

ENTRYPOINT ./app

EXPOSE 8080


k8s-artifacts.yaml


apiVersion: apps/v1

kind: Deployment

metadata:

  name: testapp

spec:

  selector:

    matchLabels:

      app: testapp

  replicas: 3

  template:

    metadata:

      labels:

        app: testapp

    spec:

      containers:

        - name: testapp

          image: gcr.io/<ACCOUNT>/test  

          ports:

            - containerPort: 8080

          livenessProbe:

            initialDelaySeconds: 10

            periodSeconds: 10

            exec:

              command:

                - "true"

          readinessProbe:

            initialDelaySeconds: 5

            periodSeconds: 20

            httpGet:

              path: /health

              port: 8080

---

apiVersion: v1

kind: Service

metadata:

  name: testapp

spec:

  type: NodePort

  ports:

  - name: http

    protocol: TCP

    port: 80

    targetPort: 8080

  selector:

    app: testapp

---

apiVersion: "extensions/v1beta1"

kind: "Ingress"

metadata:

  name: "lb-2"

  namespace: "default"

spec:

  backend:

    serviceName: "testapp"

    servicePort: 80

有了這個(gè),你將至少有一個(gè)http入口,你可以通過(guò)互聯(lián)網(wǎng)訪(fǎng)問(wèn)。之后,在驗(yàn)證服務(wù)已啟動(dòng)并運(yùn)行時(shí),可以編輯負(fù)載均衡器的前端以添加 https 規(guī)則和托管證書(shū)


查看完整回答
反對(duì) 回復(fù) 2022-08-15
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)