Last active
November 23, 2021 17:13
-
-
Save FlyInk13/7d5e78c327ae022f6585de2dc805dc98 to your computer and use it in GitHub Desktop.
Example k8s config with ingress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# export KUBECONFIG=~/.kube/kubeconfig.yaml | |
# kubectl apply -f app.yaml | |
# Deployment: app1-pods - cluster backend app | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: basic-server-image | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: app1-pods | |
template: | |
metadata: | |
labels: | |
app: app1-pods | |
spec: | |
containers: | |
- name: basic-server-image | |
image: ghcr.io/flyink13/basic-server-image:latest | |
env: | |
- name: BACKEND | |
value: "app1" | |
ports: | |
- containerPort: 80 | |
imagePullSecrets: | |
# kubectl create secret docker-registry guthub-docker-registry --docker-server=ghcr.io --docker-username=**** --docker-password=****** --docker-email=****@***.** | |
- name: guthub-docker-registry | |
--- | |
# Service: app1-pods:80 > app1-service:80 | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: app1-service | |
spec: | |
selector: | |
app: app1-pods | |
ports: | |
- protocol: TCP | |
port: 80 | |
targetPort: 80 | |
--- | |
# ClusterIssuer: certbot - https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes-ru | |
--- | |
apiVersion: cert-manager.io/v1alpha2 | |
kind: ClusterIssuer | |
metadata: | |
name: letsencrypt-prod | |
namespace: cert-manager | |
spec: | |
acme: | |
server: https://acme-v02.api.letsencrypt.org/directory | |
email: [email protected] | |
privateKeySecretRef: | |
name: letsencrypt-prod | |
solvers: | |
- http01: | |
ingress: | |
class: nginx | |
--- | |
# Ingress: default - https://kubernetes.io/docs/concepts/services-networking/ingress/ | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: app1-ingress | |
annotations: | |
kubernetes.io/ingress.class: "nginx" | |
cert-manager.io/cluster-issuer: "letsencrypt-prod" | |
spec: | |
tls: | |
- hosts: | |
- kube.ifx.su | |
secretName: ifx-tls | |
defaultBackend: | |
service: | |
name: app1-service | |
port: | |
number: 80 | |
rules: | |
- host: kube.ifx.su | |
http: | |
paths: | |
- path: / | |
pathType: Prefix | |
backend: | |
service: | |
name: app1-service | |
port: | |
number: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pod: app2-pod - basic server | |
--- | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: app2-pod | |
labels: | |
app: app2-pod | |
spec: | |
containers: | |
- name: basic-server-image | |
image: ghcr.io/flyink13/basic-server-image:latest | |
env: | |
- name: BACKEND | |
value: "pod2" | |
ports: | |
- containerPort: 80 | |
imagePullSecrets: | |
- name: guthub-docker-registry | |
# Service: app2-pod:80 > app2-service:81 | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: app2-service | |
spec: | |
selector: | |
app: app2-pod | |
ports: | |
- protocol: TCP | |
targetPort: 80 | |
port: 81 | |
# Ingress: kube2 | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: app2-ingress | |
annotations: | |
kubernetes.io/ingress.class: "nginx" | |
cert-manager.io/cluster-issuer: "letsencrypt-prod" | |
spec: | |
tls: | |
- hosts: | |
- kube2.ifx.su | |
secretName: ifx-tls2 | |
rules: | |
- host: kube2.ifx.su | |
http: | |
paths: | |
- path: / | |
pathType: Prefix | |
backend: | |
service: | |
name: app2-service | |
port: | |
number: 81 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment