dsk-dev kubespray 이동

This commit is contained in:
ByeonJungHun
2023-12-19 14:31:22 +09:00
parent a35325e16b
commit 5671a92148
2568 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
---
registry_namespace: "kube-system"
registry_storage_class: ""
registry_storage_access_mode: "ReadWriteOnce"
registry_disk_size: "10Gi"
registry_port: 5000
registry_replica_count: 1
# type of service: ClusterIP, LoadBalancer or NodePort
registry_service_type: "ClusterIP"
# you can specify your cluster IP address when registry_service_type is ClusterIP
registry_service_cluster_ip: ""
# you can specify your cloud provider assigned loadBalancerIP when registry_service_type is LoadBalancer
registry_service_loadbalancer_ip: ""
# annotations for managing Cloud Load Balancers
registry_service_annotations: {}
# you can specify the node port when registry_service_type is NodePort
registry_service_nodeport: ""
# name of kubernetes secret for registry TLS certs
registry_tls_secret: ""
registry_htpasswd: ""
# registry configuration
# see: https://docs.docker.com/registry/configuration/#list-of-configuration-options
registry_config:
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
http:
addr: :{{ registry_port }}
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
registry_ingress_annotations: {}
registry_ingress_host: ""
# name of kubernetes secret for registry ingress TLS certs
registry_ingress_tls_secret: ""

View File

@@ -0,0 +1,109 @@
---
- name: Registry | check registry_service_type value
fail:
msg: "registry_service_type can only be 'ClusterIP', 'LoadBalancer' or 'NodePort'"
when: registry_service_type not in ['ClusterIP', 'LoadBalancer', 'NodePort']
- name: Registry | Stop if registry_service_cluster_ip is defined when registry_service_type is not 'ClusterIP'
fail:
msg: "registry_service_cluster_ip support only compatible with ClusterIP."
when:
- registry_service_cluster_ip is defined and registry_service_cluster_ip|length > 0
- registry_service_type != "ClusterIP"
- name: Registry | Stop if registry_service_loadbalancer_ip is defined when registry_service_type is not 'LoadBalancer'
fail:
msg: "registry_service_loadbalancer_ip support only compatible with LoadBalancer."
when:
- registry_service_loadbalancer_ip is defined and registry_service_loadbalancer_ip|length > 0
- registry_service_type != "LoadBalancer"
- name: Registry | Stop if registry_service_nodeport is defined when registry_service_type is not 'NodePort'
fail:
msg: "registry_service_nodeport support only compatible with NodePort."
when:
- registry_service_nodeport is defined and registry_service_nodeport|length > 0
- registry_service_type != "NodePort"
- name: Registry | Create addon dir
file:
path: "{{ kube_config_dir }}/addons/registry"
state: directory
owner: root
group: root
mode: 0755
- name: Registry | Templates list
set_fact:
registry_templates:
- { name: registry-ns, file: registry-ns.yml, type: ns }
- { name: registry-sa, file: registry-sa.yml, type: sa }
- { name: registry-svc, file: registry-svc.yml, type: svc }
- { name: registry-secrets, file: registry-secrets.yml, type: secrets }
- { name: registry-cm, file: registry-cm.yml, type: cm }
- { name: registry-rs, file: registry-rs.yml, type: rs }
registry_templates_for_psp:
- { name: registry-psp, file: registry-psp.yml, type: psp }
- { name: registry-cr, file: registry-cr.yml, type: clusterrole }
- { name: registry-crb, file: registry-crb.yml, type: rolebinding }
- name: Registry | Append extra templates to Registry Templates list for PodSecurityPolicy
set_fact:
registry_templates: "{{ registry_templates[:2] + registry_templates_for_psp + registry_templates[2:] }}"
when:
- podsecuritypolicy_enabled
- registry_namespace != "kube-system"
- name: Registry | Append nginx ingress templates to Registry Templates list when ingress enabled
set_fact:
registry_templates: "{{ registry_templates + [item] }}"
with_items:
- [{ name: registry-ing, file: registry-ing.yml, type: ing }]
when: ingress_nginx_enabled or ingress_alb_enabled
- name: Registry | Create manifests
template:
src: "{{ item.file }}.j2"
dest: "{{ kube_config_dir }}/addons/registry/{{ item.file }}"
mode: 0644
with_items: "{{ registry_templates }}"
register: registry_manifests
when: inventory_hostname == groups['kube_control_plane'][0]
- name: Registry | Apply manifests
kube:
name: "{{ item.item.name }}"
namespace: "{{ registry_namespace }}"
kubectl: "{{ bin_dir }}/kubectl"
resource: "{{ item.item.type }}"
filename: "{{ kube_config_dir }}/addons/registry/{{ item.item.file }}"
state: "latest"
with_items: "{{ registry_manifests.results }}"
when: inventory_hostname == groups['kube_control_plane'][0]
- name: Registry | Create PVC manifests
template:
src: "{{ item.file }}.j2"
dest: "{{ kube_config_dir }}/addons/registry/{{ item.file }}"
mode: 0644
with_items:
- { name: registry-pvc, file: registry-pvc.yml, type: pvc }
register: registry_manifests
when:
- registry_storage_class != none and registry_storage_class
- registry_disk_size != none and registry_disk_size
- inventory_hostname == groups['kube_control_plane'][0]
- name: Registry | Apply PVC manifests
kube:
name: "{{ item.item.name }}"
namespace: "{{ registry_namespace }}"
kubectl: "{{ bin_dir }}/kubectl"
resource: "{{ item.item.type }}"
filename: "{{ kube_config_dir }}/addons/registry/{{ item.item.file }}"
state: "latest"
with_items: "{{ registry_manifests.results }}"
when:
- registry_storage_class != none and registry_storage_class
- registry_disk_size != none and registry_disk_size
- inventory_hostname == groups['kube_control_plane'][0]

View File

@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: registry-config
namespace: {{ registry_namespace }}
{% if registry_config %}
data:
config.yml: |-
{{ registry_config | to_yaml(indent=2, width=1337) | indent(width=4) }}
{% endif %}

View File

@@ -0,0 +1,15 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: psp:registry
namespace: {{ registry_namespace }}
rules:
- apiGroups:
- policy
resourceNames:
- registry
resources:
- podsecuritypolicies
verbs:
- use

View File

@@ -0,0 +1,13 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: psp:registry
namespace: {{ registry_namespace }}
subjects:
- kind: ServiceAccount
name: registry
namespace: {{ registry_namespace }}
roleRef:
kind: ClusterRole
name: psp:registry
apiGroup: rbac.authorization.k8s.io

View File

@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry
namespace: {{ registry_namespace }}
{% if registry_ingress_annotations %}
annotations:
{{ registry_ingress_annotations | to_nice_yaml(indent=2, width=1337) | indent(width=4) }}
{% endif %}
spec:
{% if registry_ingress_tls_secret %}
tls:
- hosts:
- {{ registry_ingress_host }}
secretName: {{ registry_ingress_tls_secret }}
{% endif %}
rules:
- host: {{ registry_ingress_host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: registry
port:
number: {{ registry_port }}

View File

@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ registry_namespace }}
labels:
name: {{ registry_namespace }}

View File

@@ -0,0 +1,44 @@
---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: registry
annotations:
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default'
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'runtime/default'
{% if apparmor_enabled %}
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
{% endif %}
labels:
addonmanager.kubernetes.io/mode: Reconcile
spec:
privileged: false
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
volumes:
- 'configMap'
- 'emptyDir'
- 'projected'
- 'secret'
- 'downwardAPI'
- 'persistentVolumeClaim'
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'RunAsAny'
seLinux:
rule: 'RunAsAny'
supplementalGroups:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
fsGroup:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
readOnlyRootFilesystem: false

View File

@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: registry-pvc
namespace: {{ registry_namespace }}
labels:
addonmanager.kubernetes.io/mode: Reconcile
spec:
accessModes:
- {{ registry_storage_access_mode }}
storageClassName: {{ registry_storage_class }}
resources:
requests:
storage: {{ registry_disk_size }}

View File

@@ -0,0 +1,115 @@
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: registry
namespace: {{ registry_namespace }}
labels:
k8s-app: registry
version: v{{ registry_image_tag }}
addonmanager.kubernetes.io/mode: Reconcile
spec:
{% if registry_storage_class != "" and registry_storage_access_mode == "ReadWriteMany" %}
replicas: {{ registry_replica_count }}
{% else %}
replicas: 1
{% endif %}
selector:
matchLabels:
k8s-app: registry
version: v{{ registry_image_tag }}
template:
metadata:
labels:
k8s-app: registry
version: v{{ registry_image_tag }}
spec:
priorityClassName: {% if registry_namespace == 'kube-system' %}system-cluster-critical{% else %}k8s-cluster-critical{% endif %}{{''}}
serviceAccountName: registry
securityContext:
fsGroup: 1000
runAsUser: 1000
containers:
- name: registry
image: {{ registry_image_repo }}:{{ registry_image_tag }}
imagePullPolicy: {{ k8s_image_pull_policy }}
command:
- /bin/registry
- serve
- /etc/docker/registry/config.yml
env:
- name: REGISTRY_HTTP_ADDR
value: :{{ registry_port }}
- name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
value: /var/lib/registry
{% if registry_htpasswd != "" %}
- name: REGISTRY_AUTH
value: "htpasswd"
- name: REGISTRY_AUTH_HTPASSWD_REALM
value: "Registry Realm"
- name: REGISTRY_AUTH_HTPASSWD_PATH
value: "/auth/htpasswd"
{% endif %}
{% if registry_tls_secret != "" %}
- name: REGISTRY_HTTP_TLS_CERTIFICATE
value: /etc/ssl/docker/tls.crt
- name: REGISTRY_HTTP_TLS_KEY
value: /etc/ssl/docker/tls.key
{% endif %}
volumeMounts:
- name: registry-pvc
mountPath: /var/lib/registry
- name: registry-config
mountPath: /etc/docker/registry
{% if registry_htpasswd != "" %}
- name: auth
mountPath: /auth
readOnly: true
{% endif %}
{% if registry_tls_secret != "" %}
- name: tls-cert
mountPath: /etc/ssl/docker
readOnly: true
{% endif %}
ports:
- containerPort: {{ registry_port }}
name: registry
protocol: TCP
livenessProbe:
httpGet:
{% if registry_tls_secret != "" %}
scheme: HTTPS
{% endif %}
path: /
port: {{ registry_port }}
readinessProbe:
httpGet:
{% if registry_tls_secret != "" %}
scheme: HTTPS
{% endif %}
path: /
port: {{ registry_port }}
volumes:
- name: registry-pvc
{% if registry_storage_class != "" %}
persistentVolumeClaim:
claimName: registry-pvc
{% else %}
emptyDir: {}
{% endif %}
- name: registry-config
configMap:
name: registry-config
{% if registry_htpasswd != "" %}
- name: auth
secret:
secretName: registry-secret
items:
- key: htpasswd
path: htpasswd
{% endif %}
{% if registry_tls_secret != "" %}
- name: tls-cert
secret:
secretName: {{ registry_tls_secret }}
{% endif %}

View File

@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: registry
namespace: {{ registry_namespace }}

View File

@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: registry-secret
namespace: {{ registry_namespace }}
type: Opaque
data:
{% if registry_htpasswd != "" %}
htpasswd: {{ registry_htpasswd | b64encode }}
{% endif %}

View File

@@ -0,0 +1,32 @@
---
apiVersion: v1
kind: Service
metadata:
name: registry
namespace: {{ registry_namespace }}
labels:
k8s-app: registry
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "KubeRegistry"
{% if registry_service_annotations %}
annotations:
{{ registry_service_annotations | to_nice_yaml(indent=2, width=1337) | indent(width=4) }}
{% endif %}
spec:
selector:
k8s-app: registry
type: {{ registry_service_type }}
{% if registry_service_type == "ClusterIP" and registry_service_cluster_ip != "" %}
clusterIP: {{ registry_service_cluster_ip }}
{% endif %}
{% if registry_service_type == "LoadBalancer" and registry_service_loadbalancer_ip != "" %}
loadBalancerIP: {{ registry_service_loadbalancer_ip }}
{% endif %}
ports:
- name: registry
port: {{ registry_port }}
protocol: TCP
targetPort: {{ registry_port }}
{% if registry_service_type == "NodePort" and registry_service_nodeport != "" %}
nodePort: {{ registry_service_nodeport }}
{% endif %}