Skip to content

Commit

Permalink
kubernetes more partial examples
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Nov 18, 2021
1 parent da71725 commit ca6a972
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docker/examples/k8s/kustomize/bases/ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:3.5
configMap:
name: ping-demo
command: ["ping", HOSTNAME]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- ../../bases/iam-iap-tunnel
transformers:
- ../../transformers/setProject
6 changes: 6 additions & 0 deletions docker/examples/k8s/ping/development-config-map.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ping-demo
data:
hostname: "code-maven.com"
10 changes: 10 additions & 0 deletions docker/examples/k8s/ping/development-namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "development",
"labels": {
"name": "development"
}
}
}
11 changes: 11 additions & 0 deletions docker/examples/k8s/ping/ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:3.5
configMap:
name: ping-demo
command: ["ping", HOSTNAME]
9 changes: 9 additions & 0 deletions docker/examples/k8s/ping/ping_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:3.5
command: ["ping", "code-maven.com"]
9 changes: 9 additions & 0 deletions docker/examples/k8s/ping/ping_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:3.5
command: ["ping", "mail.code-maven.com"]
6 changes: 6 additions & 0 deletions docker/examples/k8s/ping/production-config-map.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ping-demo
data:
hostname: "mail.code-maven.com"
10 changes: 10 additions & 0 deletions docker/examples/k8s/ping/production-namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "production",
"labels": {
"name": "production"
}
}
}
77 changes: 77 additions & 0 deletions docker/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ minikube ssh


```
kubectl config get-contexts
kubectl config current-context
kubectl config use-context minikube
kubectl config view
Expand Down Expand Up @@ -335,4 +337,79 @@ kubectl apply -f load_balancer.yaml

* See also this [example](https://www.digitalocean.com/community/meetup_kits/getting-started-with-containers-and-kubernetes-a-digitalocean-workshop-kit)

## Kubernetes hierarchy
{id: k8s-hierarchy}


```
Clusters
Namespaces
Users
```

* Contexts - A context is a Cluster/Namespace/User triplet (I think)

In the same cluster create 2 namespaces:
* development
* production

![](examples/k8s/ping/development-namespace.yml)
![](examples/k8s/ping/production-namespace.yml)

```
kubectl apply -f development-namespace.yml
kubectl apply -f production-namespace.yml
kubectl get namespaces --show-labels
```

We still only have the main minikube context:

```
kubectl config get-contexts
```


List the available clusters, users and namespaces:

```
kubectl config get-clusters
kubectl config get-users
kubectl get namespaces --show-labels
```

Create context for each environment:

```
kubectl config set-context development --namespace=development --cluster=minikube --user=minikube
kubectl config set-context production --namespace=production --cluster=minikube --user=minikube
```

Switch to context:

```
kubectl config use-context development
```

Alternatively we could add `--context development` at the end of the individual commands.

get the current context

```
kubectl config current-context
```


kubectl apply -f development-config-map.yml --context development


Make sure the right configuration is used in each namespace



```
kubectl apply -k base
kubectl delete -k base
kubectl kustomize base/
```

0 comments on commit ca6a972

Please sign in to comment.