initial import

This commit is contained in:
SourceFellows
2020-08-21 06:26:40 +02:00
commit e223458dd4
423 changed files with 9871 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# delve output
debug
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

2
cloud-provider/google-cloud-hello/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalDependencies">
<plugin id="com.google.gct.core" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/go-hello-world.iml" filepath="$PROJECT_DIR$/.idea/go-hello-world.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,5 @@
{
"recommendations": [
"googlecloudtools.cloudcode",
]
}

View File

@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run on Kubernetes",
"type": "cloudcode.kubernetes",
"request": "launch",
"skaffoldConfig": "${workspaceFolder}/skaffold.yaml",
"watch": true,
"cleanUp": true,
"portForward": true,
"imageRegistry": "gcr.io/gobuch-72abe"
},
{
"type": "go",
"request": "launch",
"name": "Launch (local)",
"mode": "auto",
"program": "${workspaceFolder}/cmd/hello-world"
}
]
}

View File

@ -0,0 +1,42 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"presentation": {
"panel": "shared",
"showReuseMessage": true,
},
"tasks": [
{
"group": "build",
"label": "Build container image using local Docker",
"type": "process",
"command": "skaffold",
"args": [
"build",
"-p=no-push"
],
"problemMatcher": [],
},
{
"label": "Deploy to Kubernetes cluster",
"type": "process",
"command": "skaffold",
"args": [
"run"
],
"problemMatcher": [],
},
{
"label": "View application logs on Kubernetes",
"type": "process",
"command": "kubectl",
"args": [
"logs",
"--selector",
"app=hello-world"
],
"problemMatcher": [],
}
]
}

View File

@ -0,0 +1,29 @@
# Use base golang image from Docker Hub
FROM golang:1.14
# Download the dlv (delve) debugger for go (you can comment this out if unused)
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
WORKDIR /src/hello-world
# Install dependencies in go.mod and go.sum
COPY go.mod go.sum ./
RUN go mod download
# Copy rest of the application source code
COPY . ./
# Compile the application to /app.
RUN go build -o /app -v ./cmd/hello-world
# If you want to use the debugger, you need to modify the entrypoint to the
# container and point it to the "dlv debug" command:
# * UNCOMMENT the following ENTRYPOINT statement,
# * COMMENT OUT the last ENTRYPOINT statement
# Start the "dlv debug" server on port 3000 of the container.
ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]
# If you want to run WITHOUT the debugging server:
# * COMMENT OUT the previous ENTRYPOINT statements,
# * UNCOMMENT the following ENTRYPOINT statement.
# ENTRYPOINT ["/app"]

View File

@ -0,0 +1,73 @@
# Hello World with Cloud Code
![Architecture Diagram](./img/diagram.png)
"Hello World" is a simple Kubernetes application that contains a single
[Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) and a corresponding
[Service](https://kubernetes.io/docs/concepts/services-networking/service/). The Deployment contains a
web server that simply prints "Hello World".
----
## Table of Contents
* [VS Code Guide](#vs-code-guide)
1. [Getting Started](#vs-code-getting-started)
2. [What's in the box](https://cloud.google.com/code/docs/vscode/quickstart#whats_in_the_box)
* [IntelliJ Guide](#intellij-guide)
1. [Getting Started](#intellij-getting-started)
2. [What's in the box](https://cloud.google.com/code/docs/intellij/quickstart#whats_in_the_box)
* [Using the Command Line](#using-the-command-line)
----
## VS Code Guide
### VS Code Getting Started
This sample was written to demonstrate how to use the Cloud Code extension for Visual Studio Code.
* [Install Cloud Code for VS Code](https://cloud.google.com/code/docs/vscode/install)
* [Creating a new app](https://cloud.google.com/code/docs/vscode/creating-an-application)
* [Editing YAML files](https://cloud.google.com/code/docs/vscode/yaml-editing)
### Using Cloud Code
* [Set up a Google Kubernetes Engine Cluster](https://cloud.google.com/code/docs/vscode/quickstart#creating_a_google_kubernetes_engine_cluster)
* [Running the app](https://cloud.google.com/code/docs/vscode/quickstart#running_your_app)
* [Debug the app](https://cloud.google.com/code/docs/vscode/quickstart#debugging_your_app)
* [View Container Logs](https://cloud.google.com/code/docs/vscode/quickstart#viewing_logs)
* [Open a Terminal in Your Container](https://cloud.google.com/code/docs/vscode/quickstart#bonus_opening_a_terminal_in_your_container)
----
## IntelliJ Guide
### IntelliJ Getting Started
This sample was written to demonstrate how to use the Cloud Code plugin for IntelliJ.
* [Install Cloud Code for IntelliJ](https://cloud.google.com/code/docs/intellij/install)
* [Creating a new app](https://cloud.google.com/code/docs/intellij/creating-a-k8-app)
* [Editing YAML files](https://cloud.google.com/code/docs/intellij/yaml-editing)
### Using Cloud Code
* [Creating an app](https://cloud.google.com/code/docs/intellij/quickstart-k8s#creating_an_application)
* [Develop an app](https://cloud.google.com/code/docs/intellij/quickstart-k8s#developing_your_application)
* [Debug an app](https://cloud.google.com/code/docs/intellij/quickstart-k8s#debugging_your_application)
* [View Container Logs](https://cloud.google.com/code/docs/intellij/quickstart-k8s#viewing_logs)
----
## Using the Command Line
As an alternative to using Cloud Code, the application can be deployed to a cluster using standard command line tools
#### Skaffold
[Skaffold](https://github.com/GoogleContainerTools/skaffold) is a command line tool that can be used to build, push, and deploy your container images
```bash
skaffold run --default-repo=gcr.io/YOUR-PROJECT-ID-HERE/cloudcode
```
#### kubectl
[kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) is the official Kubernetes command line tool. It can be used to deploy Kubernetes manifests to your cluster, but images must be build separately using another tool (for example, using the [Docker CLI](https://docs.docker.com/engine/reference/commandline/cli/))

View File

@ -0,0 +1,31 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
)
const defaultAddr = ":8080"
// main starts an http server on the $PORT environment variable.
func main() {
addr := defaultAddr
// $PORT environment variable is provided in the Kubernetes deployment.
if p := os.Getenv("PORT"); p != "" {
addr = ":" + p
}
log.Printf("server starting to listen on %s", addr)
http.HandleFunc("/", home)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalf("server listen error: %+v", err)
}
}
// home logs the received request and returns a simple response.
func home(w http.ResponseWriter, r *http.Request) {
log.Printf("received request: %s %s", r.Method, r.URL.Path)
fmt.Fprintf(w, "Hello, world!")
}

View File

@ -0,0 +1,3 @@
module hello-world
go 1.12

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -0,0 +1,27 @@
# This Deployment manifest defines:
# - single-replica deployment of the container image, with label "app: go-hello-world"
# - Pod exposes port 8080
# - specify PORT environment variable to the container process
# Syntax reference https://kubernetes.io/docs/concepts/configuration/overview/
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-hello-world
spec:
replicas: 1
selector:
matchLabels:
app: go-hello-world
template:
metadata:
labels:
app: go-hello-world
spec:
containers:
- name: server
image: go-hello-world
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"

View File

@ -0,0 +1,17 @@
# This Service manifest defines:
# - a load balancer for pods matching label "app: go-hello-world"
# - exposing the application to the public Internet (type:LoadBalancer)
# - routes port 80 of the load balancer to the port 8080 of the Pods.
# Syntax reference https://kubernetes.io/docs/concepts/configuration/overview/
apiVersion: v1
kind: Service
metadata:
name: go-hello-world-external
spec:
type: LoadBalancer
selector:
app: go-hello-world
ports:
- name: http
port: 80
targetPort: 8080

View File

@ -0,0 +1,16 @@
apiVersion: skaffold/v1beta15
kind: Config
build:
tagPolicy:
sha256: {}
artifacts:
- context: .
image: go-hello-world
deploy:
kubectl:
manifests:
- kubernetes-manifests/**
profiles:
- name: cloudbuild
build:
googleCloudBuild: {}