新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
75
learn/learn-kubernetes-master/kiamol/ch20/lab/README.md
Normal file
75
learn/learn-kubernetes-master/kiamol/ch20/lab/README.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# Ch20 lab
|
||||
|
||||
## Setup
|
||||
|
||||
Deploy the custom controller:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/timecheck-controller/
|
||||
```
|
||||
|
||||
Try to create custom resource:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/timecheck-test.yaml
|
||||
```
|
||||
|
||||
Check the controller logs:
|
||||
|
||||
```
|
||||
kubectl logs -l app=timecheck-controller --tail 100
|
||||
```
|
||||
|
||||
> This controller doesn't handle the situation where the CRD doesn't exist, so the container exits and the Pod will keep restarting
|
||||
|
||||
## Sample Solution
|
||||
|
||||
The [CRD](./solution/timecheck-crd.yaml) specifies the structure of the custom timecheck resource.
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/timecheck-crd.yaml
|
||||
```
|
||||
|
||||
Restart the controller - it will be in CrashLoopBackOff status by now:
|
||||
|
||||
```
|
||||
kubectl delete pods -l app=timecheck-controller
|
||||
```
|
||||
|
||||
Now you can create the custom resource:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/timecheck-test.yaml
|
||||
```
|
||||
|
||||
Check the controller has created a Deployment:
|
||||
|
||||
```
|
||||
kubectl logs -l app=timecheck-controller --tail 4
|
||||
```
|
||||
|
||||
List the timecheck resources:
|
||||
|
||||
```
|
||||
kubectl get tc
|
||||
```
|
||||
|
||||
And check the logs from the timecheck app:
|
||||
|
||||
```
|
||||
kubectl logs -l app=timecheck -c logger
|
||||
```
|
||||
|
||||
## Teardown
|
||||
|
||||
Delete the CRD:
|
||||
|
||||
```
|
||||
kubectl delete crd timechecks.ch20.kiamol.net
|
||||
```
|
||||
|
||||
And the controller:
|
||||
|
||||
```
|
||||
kubectl delete -f lab/timecheck-controller/
|
||||
```
|
||||
@@ -0,0 +1,39 @@
|
||||
apiVersion: apiextensions.k8s.io/v1 # minimum 1.16
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: timechecks.ch20.kiamol.net
|
||||
labels:
|
||||
kiamol: ch20
|
||||
spec:
|
||||
group: ch20.kiamol.net
|
||||
scope: Namespaced
|
||||
names:
|
||||
plural: timechecks
|
||||
singular: timecheck
|
||||
kind: TimeCheck
|
||||
shortNames:
|
||||
- tc
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
schema:
|
||||
openAPIV3Schema:
|
||||
type: object
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
properties:
|
||||
environment:
|
||||
type: string
|
||||
interval:
|
||||
type: integer
|
||||
additionalPrinterColumns:
|
||||
- name: Environment
|
||||
type: string
|
||||
description: Environment
|
||||
jsonPath: .spec.environment
|
||||
- name: Interval
|
||||
type: string
|
||||
description: Interval
|
||||
jsonPath: .spec.interval
|
||||
@@ -0,0 +1,7 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: timecheck-controller
|
||||
labels:
|
||||
kiamol: ch20-lab
|
||||
automountServiceAccountToken: false
|
||||
@@ -0,0 +1,28 @@
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: timecheck-controller
|
||||
labels:
|
||||
kiamol: ch20-lab
|
||||
rules:
|
||||
- apiGroups: ["apps"]
|
||||
resources: ["deployments"]
|
||||
verbs: ["list", "create", "delete"]
|
||||
- apiGroups: ["ch20.kiamol.net"]
|
||||
resources: ["timechecks"]
|
||||
verbs: ["list", "watch"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: timecheck-controller
|
||||
labels:
|
||||
kiamol: ch20-lab
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: timecheck-controller
|
||||
namespace: default
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: timecheck-controller
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: timecheck-controller
|
||||
labels:
|
||||
kiamol: ch20-lab
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: timecheck-controller
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: timecheck-controller
|
||||
spec:
|
||||
serviceAccountName: timecheck-controller
|
||||
automountServiceAccountToken: true
|
||||
containers:
|
||||
- image: kiamol/ch20-timecheck-controller
|
||||
name: controller
|
||||
@@ -0,0 +1,9 @@
|
||||
apiVersion: "ch20.kiamol.net/v1"
|
||||
kind: TimeCheck
|
||||
metadata:
|
||||
name: test
|
||||
labels:
|
||||
kiamol: ch20-lab
|
||||
spec:
|
||||
environment: TEST
|
||||
interval: 10
|
||||
Reference in New Issue
Block a user