Merge remote-tracking branch 'upstream/master' into registry-change

# Conflicts:
#	guestbook-go/guestbook-controller.json
#	guestbook-go/redis-master-controller.json
#	guestbook-go/redis-replica-controller.json

Signed-off-by: ajayk <ajaykemparaj@gmail.com>
This commit is contained in:
ajayk 2023-02-08 16:04:26 -08:00
commit fd7fa0f969
16 changed files with 176 additions and 201 deletions

37
dev/cd/after-push-to-branch Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"
if [ -z "${GIT_REF:-}" ]; then
echo "GIT_REF must be set"
exit 1
fi
if [[ -z "${REGISTRY_BASE:-}" ]]; then
echo "REGISTRY_BASE must be set"
exit 1
fi
if [[ ! "${GIT_REF}" =~ ^refs/heads/.* ]]; then
echo "GIT_REF=${GIT_REF} is not of the expected format refs/heads/*"
exit 1
fi
BRANCH=${GIT_REF/refs\/heads\//}
echo "BRANCH is ${BRANCH}"
GIT_REVISION=$(git rev-parse --short HEAD)
echo "GIT_REVISION is ${GIT_REVISION}"
export IMAGE_TAG="g${GIT_REVISION}"
echo "IMAGE_TAG is ${IMAGE_TAG}"
pushd ${REPO_ROOT}/guestbook-go
VERSION=${IMAGE_TAG} REGISTRY=${REGISTRY_BASE} make push
popd

View File

@ -0,0 +1,13 @@
timeout: 900s
steps:
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230111-cd1b3caf9c'
entrypoint: dev/cd/after-push-to-branch
env:
- GIT_REF=$_GIT_TAG
- PULL_BASE_REF=$_PULL_BASE_REF
- REGISTRY_BASE=gcr.io/k8s-staging-examples
substitutions:
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
# can be used as a substitution
_GIT_TAG: '12345'
_PULL_BASE_REF: 'master'

View File

@ -23,11 +23,11 @@ release: clean build push clean
# builds a docker image that builds the app and packages it into a minimal docker image # builds a docker image that builds the app and packages it into a minimal docker image
build: build:
docker build -t ${REGISTRY}/guestbook:${VERSION} . docker buildx build --load -t ${REGISTRY}/guestbook:${VERSION} .
# push the image to an registry # push the image to an registry
push: push:
gcloud docker -- push ${REGISTRY}/guestbook:${VERSION} docker buildx build --push -t ${REGISTRY}/guestbook:${VERSION} .
# remove previous images and containers # remove previous images and containers
clean: clean:

View File

@ -24,12 +24,12 @@ This example assumes that you have a working cluster. See the [Getting Started G
### Step One: Create the Redis master pod<a id="step-one"></a> ### Step One: Create the Redis master pod<a id="step-one"></a>
Use the `examples/guestbook-go/redis-master-controller.json` file to create a [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) and Redis master [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/). The pod runs a Redis key-value server in a container. Using a replication controller is the preferred way to launch long-running pods, even for 1 replica, so that the pod benefits from the self-healing mechanism in Kubernetes (keeps the pods alive). Use the `examples/guestbook-go/redis-master-controller.yaml` file to create a [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) and Redis master [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/). The pod runs a Redis key-value server in a container. Using a replication controller is the preferred way to launch long-running pods, even for 1 replica, so that the pod benefits from the self-healing mechanism in Kubernetes (keeps the pods alive).
1. Use the [redis-master-controller.json](redis-master-controller.json) file to create the Redis master replication controller in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command: 1. Use the [redis-master-controller.yaml](redis-master-controller.yaml) file to create the Redis master replication controller in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/redis-master-controller.json $ kubectl create -f examples/guestbook-go/redis-master-controller.yaml
``` ```
@ -73,10 +73,10 @@ A Kubernetes [service](https://kubernetes.io/docs/concepts/services-networking/s
Services find the pods to load balance based on pod labels. The pod that you created in Step One has the label `app=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service. Services find the pods to load balance based on pod labels. The pod that you created in Step One has the label `app=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service.
1. Use the [redis-master-service.json](redis-master-service.json) file to create the service in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command: 1. Use the [redis-master-service.yaml](redis-master-service.yaml) file to create the service in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/redis-master-service.json $ kubectl create -f examples/guestbook-go/redis-master-service.yaml
``` ```
@ -96,10 +96,10 @@ Services find the pods to load balance based on pod labels. The pod that you cre
The Redis master we created earlier is a single pod (REPLICAS = 1), while the Redis read replicas we are creating here are 'replicated' pods. In Kubernetes, a replication controller is responsible for managing the multiple instances of a replicated pod. The Redis master we created earlier is a single pod (REPLICAS = 1), while the Redis read replicas we are creating here are 'replicated' pods. In Kubernetes, a replication controller is responsible for managing the multiple instances of a replicated pod.
1. Use the file [redis-replica-controller.json](redis-replica-controller.json) to create the replication controller by running the `kubectl create -f` *`filename`* command: 1. Use the file [redis-replica-controller.yaml](redis-replica-controller.yaml) to create the replication controller by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/redis-replica-controller.json $ kubectl create -f examples/guestbook-go/redis-replica-controller.yaml
``` ```
@ -139,10 +139,10 @@ The Redis master we created earlier is a single pod (REPLICAS = 1), while the Re
Just like the master, we want to have a service to proxy connections to the read replicas. In this case, in addition to discovery, the Redis replica service provides transparent load balancing to clients. Just like the master, we want to have a service to proxy connections to the read replicas. In this case, in addition to discovery, the Redis replica service provides transparent load balancing to clients.
1. Use the [redis-replica-service.json](redis-replica-service.json) file to create the Redis replica service by running the `kubectl create -f` *`filename`* command: 1. Use the [redis-replica-service.yaml](redis-replica-service.yaml) file to create the Redis replica service by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/redis-replica-service.json $ kubectl create -f examples/guestbook-go/redis-replica-service.yaml
``` ```
@ -164,14 +164,14 @@ Tip: It is helpful to set labels on your services themselves--as we've done here
This is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni) based) server that is configured to talk to either the replica or master services depending on whether the request is a read or a write. The pods we are creating expose a simple JSON interface and serves a jQuery-Ajax based UI. Like the Redis replica pods, these pods are also managed by a replication controller. This is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni) based) server that is configured to talk to either the replica or master services depending on whether the request is a read or a write. The pods we are creating expose a simple JSON interface and serves a jQuery-Ajax based UI. Like the Redis replica pods, these pods are also managed by a replication controller.
1. Use the [guestbook-controller.json](guestbook-controller.json) file to create the guestbook replication controller by running the `kubectl create -f` *`filename`* command: 1. Use the [guestbook-controller.yaml](guestbook-controller.yaml) file to create the guestbook replication controller by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/guestbook-controller.json $ kubectl create -f examples/guestbook-go/guestbook-controller.yaml
``` ```
Tip: If you want to modify the guestbook code open the `_src` of this example and read the README.md and the Makefile. If you have pushed your custom image be sure to update the `image` accordingly in the guestbook-controller.json. Tip: If you want to modify the guestbook code open the `_src` of this example and read the README.md and the Makefile. If you have pushed your custom image be sure to update the `image` accordingly in the guestbook-controller.yaml.
2. To verify that the guestbook replication controller is running, run the `kubectl get rc` command: 2. To verify that the guestbook replication controller is running, run the `kubectl get rc` command:
@ -204,10 +204,10 @@ This is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni
Just like the others, we create a service to group the guestbook pods but this time, to make the guestbook front end externally visible, we specify `"type": "LoadBalancer"`. Just like the others, we create a service to group the guestbook pods but this time, to make the guestbook front end externally visible, we specify `"type": "LoadBalancer"`.
1. Use the [guestbook-service.json](guestbook-service.json) file to create the guestbook service by running the `kubectl create -f` *`filename`* command: 1. Use the [guestbook-service.yaml](guestbook-service.yaml) file to create the guestbook service by running the `kubectl create -f` *`filename`* command:
```console ```console
$ kubectl create -f examples/guestbook-go/guestbook-service.json $ kubectl create -f examples/guestbook-go/guestbook-service.yaml
``` ```

View File

@ -1,37 +0,0 @@
{
"kind":"ReplicationController",
"apiVersion":"v1",
"metadata":{
"name":"guestbook",
"labels":{
"app":"guestbook"
}
},
"spec":{
"replicas":3,
"selector":{
"app":"guestbook"
},
"template":{
"metadata":{
"labels":{
"app":"guestbook"
}
},
"spec":{
"containers":[
{
"name":"guestbook",
"image":"registry.k8s.io/guestbook:v3",
"ports":[
{
"name":"http-server",
"containerPort":3000
}
]
}
]
}
}
}
}

View File

@ -0,0 +1,21 @@
kind: ReplicationController
apiVersion: v1
metadata:
name: guestbook
labels:
app: guestbook
spec:
replicas: 3
selector:
app: guestbook
template:
metadata:
labels:
app: guestbook
spec:
containers:
- name: guestbook
image: k8s.gcr.io/guestbook:v3
ports:
- name: http-server
containerPort: 3000

View File

@ -1,22 +0,0 @@
{
"kind":"Service",
"apiVersion":"v1",
"metadata":{
"name":"guestbook",
"labels":{
"app":"guestbook"
}
},
"spec":{
"ports": [
{
"port":3000,
"targetPort":"http-server"
}
],
"selector":{
"app":"guestbook"
},
"type": "LoadBalancer"
}
}

View File

@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: guestbook
labels:
app: guestbook
spec:
ports:
- port: 3000
targetPort: http-server
selector:
app: guestbook
type: LoadBalancer

View File

@ -1,40 +0,0 @@
{
"kind":"ReplicationController",
"apiVersion":"v1",
"metadata":{
"name":"redis-master",
"labels":{
"app":"redis",
"role":"master"
}
},
"spec":{
"replicas":1,
"selector":{
"app":"redis",
"role":"master"
},
"template":{
"metadata":{
"labels":{
"app":"redis",
"role":"master"
}
},
"spec":{
"containers":[
{
"name":"redis-master",
"image":"registry.k8s.io/redis:e2e",
"ports":[
{
"name":"redis-server",
"containerPort":6379
}
]
}
]
}
}
}
}

View File

@ -0,0 +1,24 @@
kind: ReplicationController
apiVersion: v1
metadata:
name: redis-master
labels:
app: redis
role: master
spec:
replicas: 1
selector:
app: redis
role: master
template:
metadata:
labels:
app: redis
role: master
spec:
containers:
- name: redis-master
image: k8s.gcr.io/redis:e2e
ports:
- name: redis-server
containerPort: 6379

View File

@ -1,23 +0,0 @@
{
"kind":"Service",
"apiVersion":"v1",
"metadata":{
"name":"redis-master",
"labels":{
"app":"redis",
"role":"master"
}
},
"spec":{
"ports": [
{
"port":6379,
"targetPort":"redis-server"
}
],
"selector":{
"app":"redis",
"role":"master"
}
}
}

View File

@ -0,0 +1,14 @@
kind: Service
apiVersion: v1
metadata:
name: redis-master
labels:
app: redis
role: master
spec:
ports:
- port: 6379
targetPort: redis-server
selector:
app: redis
role: master

View File

@ -1,40 +0,0 @@
{
"kind":"ReplicationController",
"apiVersion":"v1",
"metadata":{
"name":"redis-replica",
"labels":{
"app":"redis",
"role":"replica"
}
},
"spec":{
"replicas":2,
"selector":{
"app":"redis",
"role":"replica"
},
"template":{
"metadata":{
"labels":{
"app":"redis",
"role":"replica"
}
},
"spec":{
"containers":[
{
"name":"redis-replica",
"image":"registry.k8s.io/redis-slave:v2",
"ports":[
{
"name":"redis-server",
"containerPort":6379
}
]
}
]
}
}
}
}

View File

@ -0,0 +1,24 @@
kind: ReplicationController
apiVersion: v1
metadata:
name: redis-replica
labels:
app: redis
role: replica
spec:
replicas: 2
selector:
app: redis
role: replica
template:
metadata:
labels:
app: redis
role: replica
spec:
containers:
- name: redis-replica
image: k8s.gcr.io/redis-slave:v2
ports:
- name: redis-server
containerPort: 6379

View File

@ -1,23 +0,0 @@
{
"kind":"Service",
"apiVersion":"v1",
"metadata":{
"name":"redis-replica",
"labels":{
"app":"redis",
"role":"replica"
}
},
"spec":{
"ports": [
{
"port":6379,
"targetPort":"redis-server"
}
],
"selector":{
"app":"redis",
"role":"replica"
}
}
}

View File

@ -0,0 +1,14 @@
kind: Service
apiVersion: v1
metadata:
name: redis-replica
labels:
app: redis
role: replica
spec:
ports:
- port: 6379
targetPort: redis-server
selector:
app: redis
role: replica