|
| 1 | +{{- if .Values.configuration.portHTTPS }} |
| 2 | +apiVersion: v1 |
| 3 | +kind: PersistentVolumeClaim |
| 4 | +metadata: |
| 5 | + name: {{ .Values.application.appName }}-data |
| 6 | +spec: |
| 7 | + accessModes: |
| 8 | + - ReadWriteOnce |
| 9 | + storageClassName: local-path |
| 10 | + resources: |
| 11 | + requests: |
| 12 | + storage: 2Gi |
| 13 | +--- |
| 14 | +apiVersion: v1 |
| 15 | +kind: ConfigMap |
| 16 | +metadata: |
| 17 | + name: {{ .Values.application.appName }} |
| 18 | +data: |
| 19 | + default.conf: | |
| 20 | + user root root; |
| 21 | + |
| 22 | + worker_processes auto; |
| 23 | + |
| 24 | + error_log /var/log/nginx/error.log notice; |
| 25 | + pid /var/run/nginx.pid; |
| 26 | + |
| 27 | + events { |
| 28 | + worker_connections 1024; |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + http { |
| 33 | + include /etc/nginx/mime.types; |
| 34 | + default_type application/octet-stream; |
| 35 | + |
| 36 | + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 37 | + '$status $body_bytes_sent "$http_referer" ' |
| 38 | + '"$http_user_agent" "$http_x_forwarded_for"'; |
| 39 | + |
| 40 | + access_log /var/log/nginx/access.log main; |
| 41 | + |
| 42 | + sendfile on; |
| 43 | + #tcp_nopush on; |
| 44 | + |
| 45 | + keepalive_timeout 65; |
| 46 | + |
| 47 | + #gzip on; |
| 48 | + |
| 49 | + server { |
| 50 | + listen 80 default_server; |
| 51 | + listen [::]:80 default_server; |
| 52 | + server_name server_domain_or_IP; |
| 53 | + return 302 https://$server_name$request_uri; |
| 54 | + } |
| 55 | + server { |
| 56 | + disable_symlinks off; |
| 57 | + # SSL configuration |
| 58 | + listen {{ .Values.configuration.portHTTPS }} ssl http2 default_server; |
| 59 | + listen [::]:{{ .Values.configuration.portHTTPS }} ssl http2 default_server; |
| 60 | + ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; |
| 61 | + ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; |
| 62 | + # from https://cipherli.st/ |
| 63 | + # and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html |
| 64 | + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
| 65 | + ssl_prefer_server_ciphers on; |
| 66 | + ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; |
| 67 | + ssl_ecdh_curve secp384r1; |
| 68 | + ssl_session_cache shared:SSL:10m; |
| 69 | + ssl_session_tickets off; |
| 70 | + ssl_stapling on; |
| 71 | + ssl_stapling_verify on; |
| 72 | + resolver 8.8.8.8 8.8.4.4 valid=300s; |
| 73 | + resolver_timeout 5s; |
| 74 | + # Disable preloading HSTS for now. You can use the commented out header line that includes |
| 75 | + # the "preload" directive if you understand the implications. |
| 76 | + #add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; |
| 77 | + add_header Strict-Transport-Security "max-age=63072000; includeSubdomains"; |
| 78 | + add_header X-Frame-Options DENY; |
| 79 | + add_header X-Content-Type-Options nosniff; |
| 80 | + ssl_dhparam /etc/ssl/certs/dhparam.pem; |
| 81 | + root /var/www/html; |
| 82 | + server_name _; |
| 83 | + location / { |
| 84 | + # First attempt to serve request as file, then |
| 85 | + # as directory, then fall back to displaying a 404. |
| 86 | + try_files $uri $uri/ =404; |
| 87 | + # proxy_pass http://localhost:8080; |
| 88 | + # proxy_http_version 1.1; |
| 89 | + # proxy_set_header Upgrade $http_upgrade; |
| 90 | + # proxy_set_header Connection 'upgrade'; |
| 91 | + # proxy_set_header Host $host; |
| 92 | + # proxy_cache_bypass $http_upgrade; |
| 93 | + } |
| 94 | + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 |
| 95 | + # |
| 96 | + #location ~ \.php$ { |
| 97 | + # include snippets/fastcgi-php.conf; |
| 98 | + # |
| 99 | + # # With php7.0-cgi alone: |
| 100 | + # fastcgi_pass 127.0.0.1:9000; |
| 101 | + # # With php7.0-fpm: |
| 102 | + # fastcgi_pass unix:/run/php/php7.0-fpm.sock; |
| 103 | + #} |
| 104 | + # deny access to .htaccess files, if Apache's document root |
| 105 | + # concurs with nginx's one |
| 106 | + # |
| 107 | + #location ~ /\.ht { |
| 108 | + # deny all; |
| 109 | + #} |
| 110 | + } |
| 111 | + } |
| 112 | + k3s-start.sh: | |
| 113 | + #!/bin/bash |
| 114 | + # |
| 115 | + curl -sflkO https://{{ default .Values.configuration.hostIP .Values.configuration.externalHostIP}}:{{ .Values.configuration.portHTTPS }}/token.{{ .Values.configuration.id }} |
| 116 | + curl -sflkO https://{{ default .Values.configuration.hostIP .Values.configuration.externalHostIP}}:{{ .Values.configuration.portHTTPS }}/k3s.yaml.{{ .Values.configuration.id }} |
| 117 | + export INSTALL_K3S_VERSION=$(echo "{{ default .Chart.AppVersion .Values.image.tag }}" | sed -e "s/-k3/+k3/") |
| 118 | + export K3S_TOKEN=$(cat token.{{ .Values.configuration.id }}) |
| 119 | + export K3S_URL=$(grep server: k3s.yaml.{{ .Values.configuration.id }} | sed -e "s/^ *.server: *//") |
| 120 | +
|
| 121 | + curl -sfL https://get.k3s.io | \\ |
| 122 | + sh -s - \\ |
| 123 | + --kubelet-arg cluster-dns=169.254.0.2 \\ |
| 124 | + --log /var/log/k3s.log \\ |
| 125 | + --node-label smarter.nodetype=unknown \\ |
| 126 | + --node-label smarter.nodemodel=unknown \\ |
| 127 | + --node-label smarter.type=edge \\ |
| 128 | + --node-taint smarter.type=edge:NoSchedule \\ |
| 129 | + --node-label smarter-build=user-installed |
| 130 | +--- |
| 131 | +{{- end }} |
| 132 | +apiVersion: apps/v1 |
| 133 | +kind: Deployment |
| 134 | +metadata: |
| 135 | + name: {{ .Values.application.appName }} |
| 136 | + labels: |
| 137 | + name: {{ .Values.application.appName }} |
| 138 | +spec: |
| 139 | + selector: |
| 140 | + matchLabels: |
| 141 | + name: {{ .Values.application.appName }} |
| 142 | + template: |
| 143 | + metadata: |
| 144 | + labels: |
| 145 | + name: {{ .Values.application.appName }} |
| 146 | + annotations: |
| 147 | + node.kubernetes.io/bootstrap-checkpoint: "true" |
| 148 | + spec: |
| 149 | + containers: |
| 150 | + - name: {{ .Values.application.appName }} |
| 151 | + image: {{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }} |
| 152 | + command: [ "/bin/k3s", |
| 153 | + "server", |
| 154 | + "--tls-san","{{ .Values.configuration.hostip }}", |
| 155 | + "--advertise-address", "{{ default .Values.configuration.hostIP .Values.configuration.externalHostIP}}", |
| 156 | + "--https-listen-port", "{{ .Values.configuration.port }}", |
| 157 | + "--disable-agent", |
| 158 | + "--disable","traefik", |
| 159 | + "--disable","metrics-server", |
| 160 | + "--disable","coredns", |
| 161 | + "--disable","local-storage", |
| 162 | + "--flannel-backend=none" ] |
| 163 | + {{- if .Values.configuration.portHTTPS }} |
| 164 | + volumeMounts: |
| 165 | + - name: k3s-data |
| 166 | + mountPath: /var/lib/rancher/k3s |
| 167 | + - name: k3s-config |
| 168 | + mountPath: /etc/rancher/k3s |
| 169 | + {{- end }} |
| 170 | + ports: |
| 171 | + - containerPort: {{ .Values.configuration.port }} |
| 172 | + {{- if .Values.configuration.portHTTPS }} |
| 173 | + - name: {{ .Values.application.appName }}-nginx |
| 174 | + image: nginx:1.23.2-alpine |
| 175 | + command: [ "/bin/sh", |
| 176 | + "-c", |
| 177 | + "apk update;apk add openssl;echo -e '\n\n\n\n\n\n\n' | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt;openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048;mkdir -p /var/www/html;ln -s /etc/rancher/k3s/k3s.yaml /var/www/html/k3s.yaml.{{ .Values.configuration.id }};ln -s /var/lib/rancher/k3s/server/token /var/www/html/token.{{ .Values.configuration.id }};ln -s /etc/nginx/conf.d/k3s-start.sh /var/www/html/k3s-start.sh.{{ .Values.configuration.id }};chmod -R ago+rw /var/www/html;nginx -c /etc/nginx/conf.d/default.conf -g 'daemon off;'" ] |
| 178 | + volumeMounts: |
| 179 | + - name: k3s-data |
| 180 | + mountPath: /var/lib/rancher/k3s |
| 181 | + - name: k3s-config |
| 182 | + mountPath: /etc/rancher/k3s |
| 183 | + - name: config |
| 184 | + mountPath: /etc/nginx/conf.d |
| 185 | + ports: |
| 186 | + - containerPort: {{ .Values.configuration.portHTTPS }} |
| 187 | + {{- end }} |
| 188 | + volumes: |
| 189 | + {{- if .Values.configuration.portHTTPS }} |
| 190 | + - name: k3s-data |
| 191 | + persistentVolumeClaim: |
| 192 | + claimName: {{ .Values.application.appName }}-data |
| 193 | + - name: k3s-config |
| 194 | + emptyDir: {} |
| 195 | + - name: config |
| 196 | + configMap: |
| 197 | + name: {{ .Values.application.appName }} |
| 198 | + {{- end }} |
0 commit comments