Skip to content

Commit 9acf541

Browse files
authored
Merge pull request #2 from sebgoa/migration
Migration
2 parents fc19138 + 3865809 commit 9acf541

File tree

372 files changed

+23461
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+23461
-3
lines changed

OWNERS

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
reviewers:
2+
- brendandburns
3+
- thockin
4+
- zmerlynn
5+
approvers:
6+
- brendandburns
7+
- eparis
8+
- thockin
9+
- zmerlynn

README.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
# examples
2-
Kubernetes application example tutorials
1+
# Kubernetes Examples: releases.k8s.io/HEAD
32

4-
Home for examples to be moved from kubernetes/kubernetes/examples
3+
This directory contains a number of examples of how to run
4+
real applications with Kubernetes.
5+
6+
Demonstrations of how to use specific Kubernetes features can be found in our [documents](../docs/).
7+
8+
9+
### Maintained Examples
10+
11+
Maintained Examples are expected to be updated with every Kubernetes
12+
release, to use the latest and greatest features, current guidelines
13+
and best practices, and to refresh command syntax, output, changed
14+
prerequisites, as needed.
15+
16+
|Name | Description | Notable Features Used | Complexity Level|
17+
------------- | ------------- | ------------ | ------------ |
18+
|[Guestbook](guestbook/) | PHP app with Redis | Replication Controller, Service | Beginner |
19+
|[WordPress](mysql-wordpress-pd/) | WordPress with MySQL | Deployment, Persistent Volume with Claim | Beginner|
20+
|[Cassandra](storage/cassandra/) | Cloud Native Cassandra | Daemon Set | Intermediate
21+
22+
* Note: Please add examples to the list above that are maintained.
23+
24+
See [Example Guidelines](guidelines.md) for a description of what goes
25+
in this directory, and what examples should contain.

staging/BUILD

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"])
4+
5+
load(
6+
"@io_bazel_rules_go//go:def.bzl",
7+
"go_library",
8+
"go_test",
9+
)
10+
11+
filegroup(
12+
name = "config",
13+
srcs = glob([
14+
"**/*.yaml",
15+
"**/*.yml",
16+
"**/*.json",
17+
]) + [
18+
"pod",
19+
],
20+
)
21+
22+
filegroup(
23+
name = "sources",
24+
srcs = glob([
25+
"**/*",
26+
]),
27+
)
28+
29+
go_library(
30+
name = "go_default_library",
31+
srcs = ["doc.go"],
32+
tags = ["automanaged"],
33+
)
34+
35+
go_test(
36+
name = "go_default_xtest",
37+
srcs = ["examples_test.go"],
38+
tags = ["automanaged"],
39+
deps = [
40+
"//pkg/api:go_default_library",
41+
"//pkg/api/testapi:go_default_library",
42+
"//pkg/api/validation:go_default_library",
43+
"//pkg/apis/apps:go_default_library",
44+
"//pkg/apis/apps/validation:go_default_library",
45+
"//pkg/apis/batch:go_default_library",
46+
"//pkg/apis/extensions:go_default_library",
47+
"//pkg/apis/extensions/validation:go_default_library",
48+
"//pkg/capabilities:go_default_library",
49+
"//pkg/registry/batch/job:go_default_library",
50+
"//plugin/pkg/scheduler/api:go_default_library",
51+
"//plugin/pkg/scheduler/api/latest:go_default_library",
52+
"//vendor/github.com/golang/glog:go_default_library",
53+
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
54+
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
55+
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
56+
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
57+
"//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
58+
],
59+
)
60+
61+
filegroup(
62+
name = "package-srcs",
63+
srcs = glob(["**"]),
64+
tags = ["automanaged"],
65+
visibility = ["//visibility:private"],
66+
)
67+
68+
filegroup(
69+
name = "all-srcs",
70+
srcs = [
71+
":package-srcs",
72+
"//examples/explorer:all-srcs",
73+
"//examples/guestbook-go:all-srcs",
74+
"//examples/https-nginx:all-srcs",
75+
"//examples/sharing-clusters:all-srcs",
76+
],
77+
tags = ["automanaged"],
78+
)

staging/cluster-dns/README.md

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
## Kubernetes DNS example
2+
3+
This is a toy example demonstrating how to use kubernetes DNS.
4+
5+
### Step Zero: Prerequisites
6+
7+
This example assumes that you have forked the repository and [turned up a Kubernetes cluster](../../docs/getting-started-guides/). Make sure DNS is enabled in your setup, see [DNS doc](https://github.com/kubernetes/dns).
8+
9+
```sh
10+
$ cd kubernetes
11+
$ hack/dev-build-and-up.sh
12+
```
13+
14+
### Step One: Create two namespaces
15+
16+
We'll see how cluster DNS works across multiple [namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/), first we need to create two namespaces:
17+
18+
```sh
19+
$ kubectl create -f examples/cluster-dns/namespace-dev.yaml
20+
$ kubectl create -f examples/cluster-dns/namespace-prod.yaml
21+
```
22+
23+
Now list all namespaces:
24+
25+
```sh
26+
$ kubectl get namespaces
27+
NAME LABELS STATUS
28+
default <none> Active
29+
development name=development Active
30+
production name=production Active
31+
```
32+
33+
For kubectl client to work with each namespace, we define two contexts:
34+
35+
```sh
36+
$ kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
37+
$ kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
38+
```
39+
40+
You can view your cluster name and user name in kubernetes config at ~/.kube/config.
41+
42+
### Step Two: Create backend replication controller in each namespace
43+
44+
Use the file [`examples/cluster-dns/dns-backend-rc.yaml`](dns-backend-rc.yaml) to create a backend server [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) in each namespace.
45+
46+
```sh
47+
$ kubectl config use-context dev
48+
$ kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
49+
```
50+
51+
Once that's up you can list the pod in the cluster:
52+
53+
```sh
54+
$ kubectl get rc
55+
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
56+
dns-backend dns-backend ddysher/dns-backend name=dns-backend 1
57+
```
58+
59+
Now repeat the above commands to create a replication controller in prod namespace:
60+
61+
```sh
62+
$ kubectl config use-context prod
63+
$ kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
64+
$ kubectl get rc
65+
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
66+
dns-backend dns-backend ddysher/dns-backend name=dns-backend 1
67+
```
68+
69+
### Step Three: Create backend service
70+
71+
Use the file [`examples/cluster-dns/dns-backend-service.yaml`](dns-backend-service.yaml) to create
72+
a [service](https://kubernetes.io/docs/concepts/services-networking/service/) for the backend server.
73+
74+
```sh
75+
$ kubectl config use-context dev
76+
$ kubectl create -f examples/cluster-dns/dns-backend-service.yaml
77+
```
78+
79+
Once that's up you can list the service in the cluster:
80+
81+
```sh
82+
$ kubectl get service dns-backend
83+
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
84+
dns-backend 10.0.2.3 <none> 8000/TCP name=dns-backend 1d
85+
```
86+
87+
Again, repeat the same process for prod namespace:
88+
89+
```sh
90+
$ kubectl config use-context prod
91+
$ kubectl create -f examples/cluster-dns/dns-backend-service.yaml
92+
$ kubectl get service dns-backend
93+
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
94+
dns-backend 10.0.2.4 <none> 8000/TCP name=dns-backend 1d
95+
```
96+
97+
### Step Four: Create client pod in one namespace
98+
99+
Use the file [`examples/cluster-dns/dns-frontend-pod.yaml`](dns-frontend-pod.yaml) to create a client [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod/) in dev namespace. The client pod will make a connection to backend and exit. Specifically, it tries to connect to address `http://dns-backend.development.cluster.local:8000`.
100+
101+
```sh
102+
$ kubectl config use-context dev
103+
$ kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
104+
```
105+
106+
Once that's up you can list the pod in the cluster:
107+
108+
```sh
109+
$ kubectl get pods dns-frontend
110+
NAME READY STATUS RESTARTS AGE
111+
dns-frontend 0/1 ExitCode:0 0 1m
112+
```
113+
114+
Wait until the pod succeeds, then we can see the output from the client pod:
115+
116+
```sh
117+
$ kubectl logs dns-frontend
118+
2015-05-07T20:13:54.147664936Z 10.0.236.129
119+
2015-05-07T20:13:54.147721290Z Send request to: http://dns-backend.development.cluster.local:8000
120+
2015-05-07T20:13:54.147733438Z <Response [200]>
121+
2015-05-07T20:13:54.147738295Z Hello World!
122+
```
123+
124+
Please refer to the [source code](images/frontend/client.py) about the log. First line prints out the ip address associated with the service in dev namespace; remaining lines print out our request and server response.
125+
126+
If we switch to prod namespace with the same pod config, we'll see the same result, i.e. dns will resolve across namespace.
127+
128+
```sh
129+
$ kubectl config use-context prod
130+
$ kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
131+
$ kubectl logs dns-frontend
132+
2015-05-07T20:13:54.147664936Z 10.0.236.129
133+
2015-05-07T20:13:54.147721290Z Send request to: http://dns-backend.development.cluster.local:8000
134+
2015-05-07T20:13:54.147733438Z <Response [200]>
135+
2015-05-07T20:13:54.147738295Z Hello World!
136+
```
137+
138+
139+
#### Note about default namespace
140+
141+
If you prefer not using namespace, then all your services can be addressed using `default` namespace, e.g. `http://dns-backend.default.svc.cluster.local:8000`, or shorthand version `http://dns-backend:8000`
142+
143+
144+
### tl; dr;
145+
146+
For those of you who are impatient, here is the summary of the commands we ran in this tutorial. Remember to set first `$CLUSTER_NAME` and `$USER_NAME` to the values found in `~/.kube/config`.
147+
148+
```sh
149+
# create dev and prod namespaces
150+
kubectl create -f examples/cluster-dns/namespace-dev.yaml
151+
kubectl create -f examples/cluster-dns/namespace-prod.yaml
152+
153+
# create two contexts
154+
kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
155+
kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
156+
157+
# create two backend replication controllers
158+
kubectl config use-context dev
159+
kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
160+
kubectl config use-context prod
161+
kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
162+
163+
# create backend services
164+
kubectl config use-context dev
165+
kubectl create -f examples/cluster-dns/dns-backend-service.yaml
166+
kubectl config use-context prod
167+
kubectl create -f examples/cluster-dns/dns-backend-service.yaml
168+
169+
# create a pod in each namespace and get its output
170+
kubectl config use-context dev
171+
kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
172+
kubectl logs dns-frontend
173+
174+
kubectl config use-context prod
175+
kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
176+
kubectl logs dns-frontend
177+
```
178+
179+
180+
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
181+
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/cluster-dns/README.md?pixel)]()
182+
<!-- END MUNGE: GENERATED_ANALYTICS -->
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1
2+
kind: ReplicationController
3+
metadata:
4+
name: dns-backend
5+
labels:
6+
name: dns-backend
7+
spec:
8+
replicas: 1
9+
selector:
10+
name: dns-backend
11+
template:
12+
metadata:
13+
labels:
14+
name: dns-backend
15+
spec:
16+
containers:
17+
- name: dns-backend
18+
image: gcr.io/google_containers/example-dns-backend:v1
19+
ports:
20+
- name: backend-port
21+
containerPort: 8000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: dns-backend
5+
spec:
6+
ports:
7+
- port: 8000
8+
selector:
9+
name: dns-backend
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: dns-frontend
5+
labels:
6+
name: dns-frontend
7+
spec:
8+
containers:
9+
- name: dns-frontend
10+
image: gcr.io/google_containers/example-dns-frontend:v1
11+
command:
12+
- python
13+
- client.py
14+
- http://dns-backend.development.svc.cluster.local:8000
15+
imagePullPolicy: Always
16+
restartPolicy: Never
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2016 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM python:2.7-slim
16+
17+
COPY . /dns-backend
18+
WORKDIR /dns-backend
19+
20+
CMD ["python", "server.py"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
TAG = v1
16+
PREFIX = gcr.io/google_containers
17+
IMAGE = example-dns-backend
18+
19+
all: push
20+
21+
image:
22+
docker build --pull -t $(PREFIX)/$(IMAGE):$(TAG) .
23+
24+
push: image
25+
gcloud docker -- push $(PREFIX)/$(IMAGE)
26+
27+
clean:

0 commit comments

Comments
 (0)