Skip to content

Commit c7187cb

Browse files
authored
Merge pull request #46254 from SAShameem/KubExample
[bn] adding files in content/bn/example
2 parents bb525e7 + e2bb4e5 commit c7187cb

File tree

336 files changed

+7893
-0
lines changed

Some content is hidden

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

336 files changed

+7893
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: csr-approver
5+
rules:
6+
- apiGroups:
7+
- certificates.k8s.io
8+
resources:
9+
- certificatesigningrequests
10+
verbs:
11+
- get
12+
- list
13+
- watch
14+
- apiGroups:
15+
- certificates.k8s.io
16+
resources:
17+
- certificatesigningrequests/approval
18+
verbs:
19+
- update
20+
- apiGroups:
21+
- certificates.k8s.io
22+
resources:
23+
- signers
24+
resourceNames:
25+
- example.com/my-signer-name # example.com/* can be used to authorize for all signers in the 'example.com' domain
26+
verbs:
27+
- approve
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: csr-creator
5+
rules:
6+
- apiGroups:
7+
- certificates.k8s.io
8+
resources:
9+
- certificatesigningrequests
10+
verbs:
11+
- create
12+
- get
13+
- list
14+
- watch
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: csr-signer
5+
rules:
6+
- apiGroups:
7+
- certificates.k8s.io
8+
resources:
9+
- certificatesigningrequests
10+
verbs:
11+
- get
12+
- list
13+
- watch
14+
- apiGroups:
15+
- certificates.k8s.io
16+
resources:
17+
- certificatesigningrequests/status
18+
verbs:
19+
- update
20+
- apiGroups:
21+
- certificates.k8s.io
22+
resources:
23+
- signers
24+
resourceNames:
25+
- example.com/my-signer-name # example.com/* can be used to authorize for all signers in the 'example.com' domain
26+
verbs:
27+
- sign
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingAdmissionPolicy
3+
metadata:
4+
name: "deploy-replica-policy.example.com"
5+
spec:
6+
paramKind:
7+
apiVersion: rules.example.com/v1
8+
kind: ReplicaLimit
9+
matchConstraints:
10+
resourceRules:
11+
- apiGroups: ["apps"]
12+
apiVersions: ["v1"]
13+
operations: ["CREATE", "UPDATE"]
14+
resources: ["deployments"]
15+
validations:
16+
- expression: "object.spec.replicas <= params.maxReplicas"
17+
messageExpression: "'object.spec.replicas must be no greater than ' + string(params.maxReplicas)"
18+
reason: Invalid
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
annotations:
5+
kubernetes.io/description: |-
6+
Add endpoints write permissions to the edit and admin roles. This was
7+
removed by default in 1.22 because of CVE-2021-25740. See
8+
https://issue.k8s.io/103675. This can allow writers to direct LoadBalancer
9+
or Ingress implementations to expose backend IPs that would not otherwise
10+
be accessible, and can circumvent network policies or security controls
11+
intended to prevent/isolate access to those backends.
12+
EndpointSlices were never included in the edit or admin roles, so there
13+
is nothing to restore for the EndpointSlice API.
14+
labels:
15+
rbac.authorization.k8s.io/aggregate-to-edit: "true"
16+
name: custom:aggregate-to-edit:endpoints # you can change this if you wish
17+
rules:
18+
- apiGroups: [""]
19+
resources: ["endpoints"]
20+
verbs: ["create", "delete", "deletecollection", "patch", "update"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This policy enforces that all containers of a deployment has the image repo match the environment label of its namespace.
2+
# Except for "exempt" deployments, or any containers that do not belong to the "example.com" organization (e.g. common sidecars).
3+
# For example, if the namespace has a label of {"environment": "staging"}, all container images must be either staging.example.com/*
4+
# or do not contain "example.com" at all, unless the deployment has {"exempt": "true"} label.
5+
apiVersion: admissionregistration.k8s.io/v1
6+
kind: ValidatingAdmissionPolicy
7+
metadata:
8+
name: "image-matches-namespace-environment.policy.example.com"
9+
spec:
10+
failurePolicy: Fail
11+
matchConstraints:
12+
resourceRules:
13+
- apiGroups: ["apps"]
14+
apiVersions: ["v1"]
15+
operations: ["CREATE", "UPDATE"]
16+
resources: ["deployments"]
17+
variables:
18+
- name: environment
19+
expression: "'environment' in namespaceObject.metadata.labels ? namespaceObject.metadata.labels['environment'] : 'prod'"
20+
- name: exempt
21+
expression: "'exempt' in object.metadata.labels && object.metadata.labels['exempt'] == 'true'"
22+
- name: containers
23+
expression: "object.spec.template.spec.containers"
24+
- name: containersToCheck
25+
expression: "variables.containers.filter(c, c.image.contains('example.com/'))"
26+
validations:
27+
- expression: "variables.exempt || variables.containersToCheck.all(c, c.image.startsWith(variables.environment + '.'))"
28+
messageExpression: "'only ' + variables.environment + ' images are allowed in namespace ' + namespaceObject.metadata.name"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingAdmissionPolicy
3+
metadata:
4+
name: "demo-policy.example.com"
5+
spec:
6+
failurePolicy: Fail
7+
matchConstraints:
8+
resourceRules:
9+
- apiGroups: ["apps"]
10+
apiVersions: ["v1"]
11+
operations: ["CREATE", "UPDATE"]
12+
resources: ["deployments"]
13+
validations:
14+
- expression: "object.spec.replicas > 50"
15+
messageExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"
16+
auditAnnotations:
17+
- key: "high-replica-count"
18+
valueExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingAdmissionPolicy
3+
metadata:
4+
name: "demo-policy.example.com"
5+
spec:
6+
failurePolicy: Fail
7+
matchConstraints:
8+
resourceRules:
9+
- apiGroups: ["*"]
10+
apiVersions: ["*"]
11+
operations: ["CREATE", "UPDATE"]
12+
resources: ["*"]
13+
matchConditions:
14+
- name: 'exclude-leases' # Each match condition must have a unique name
15+
expression: '!(request.resource.group == "coordination.k8s.io" && request.resource.resource == "leases")' # Match non-lease resources.
16+
- name: 'exclude-kubelet-requests'
17+
expression: '!("system:nodes" in request.userInfo.groups)' # Match requests made by non-node users.
18+
- name: 'rbac' # Skip RBAC requests.
19+
expression: 'request.resource.group != "rbac.authorization.k8s.io"'
20+
validations:
21+
- expression: "!object.metadata.name.contains('demo') || object.metadata.namespace == 'demo'"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This is an example of how to set up cloud-controller-manager as a Daemonset in your cluster.
2+
# It assumes that your masters can run pods and has the role node-role.kubernetes.io/master
3+
# Note that this Daemonset will not work straight out of the box for your cloud, this is
4+
# meant to be a guideline.
5+
6+
---
7+
apiVersion: v1
8+
kind: ServiceAccount
9+
metadata:
10+
name: cloud-controller-manager
11+
namespace: kube-system
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: ClusterRoleBinding
15+
metadata:
16+
name: system:cloud-controller-manager
17+
roleRef:
18+
apiGroup: rbac.authorization.k8s.io
19+
kind: ClusterRole
20+
name: cluster-admin
21+
subjects:
22+
- kind: ServiceAccount
23+
name: cloud-controller-manager
24+
namespace: kube-system
25+
---
26+
apiVersion: apps/v1
27+
kind: DaemonSet
28+
metadata:
29+
labels:
30+
k8s-app: cloud-controller-manager
31+
name: cloud-controller-manager
32+
namespace: kube-system
33+
spec:
34+
selector:
35+
matchLabels:
36+
k8s-app: cloud-controller-manager
37+
template:
38+
metadata:
39+
labels:
40+
k8s-app: cloud-controller-manager
41+
spec:
42+
serviceAccountName: cloud-controller-manager
43+
containers:
44+
- name: cloud-controller-manager
45+
# for in-tree providers we use registry.k8s.io/cloud-controller-manager
46+
# this can be replaced with any other image for out-of-tree providers
47+
image: registry.k8s.io/cloud-controller-manager:v1.8.0
48+
command:
49+
- /usr/local/bin/cloud-controller-manager
50+
- --cloud-provider=[YOUR_CLOUD_PROVIDER] # Add your own cloud provider here!
51+
- --leader-elect=true
52+
- --use-service-account-credentials
53+
# these flags will vary for every cloud provider
54+
- --allocate-node-cidrs=true
55+
- --configure-cloud-routes=true
56+
- --cluster-cidr=172.17.0.0/16
57+
tolerations:
58+
# this is required so CCM can bootstrap itself
59+
- key: node.cloudprovider.kubernetes.io/uninitialized
60+
value: "true"
61+
effect: NoSchedule
62+
# these tolerations are to have the daemonset runnable on control plane nodes
63+
# remove them if your control plane nodes should not run pods
64+
- key: node-role.kubernetes.io/control-plane
65+
operator: Exists
66+
effect: NoSchedule
67+
- key: node-role.kubernetes.io/master
68+
operator: Exists
69+
effect: NoSchedule
70+
# this is to restrict CCM to only run on master nodes
71+
# the node selector may vary depending on your cluster setup
72+
nodeSelector:
73+
node-role.kubernetes.io/master: ""
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: busybox
5+
namespace: default
6+
spec:
7+
containers:
8+
- name: busybox
9+
image: busybox:1.28
10+
command:
11+
- sleep
12+
- "3600"
13+
imagePullPolicy: IfNotPresent
14+
restartPolicy: Always

0 commit comments

Comments
 (0)