Installphpngiinxotro
Installphpngiinxotro
medium.com
9-12 minutos
to this:
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
Prerequisites
Kubernetes cluster
$ kubectl cluster-info
For a NodeJS app start with creating the following two files in
your NodeJS root directory, i.e. where your index.js file is.
node_modules
npm-debug.log
Now build your NodeJS app’s Docker image and push it to your
private repository.
apiVersion: apps/v1
kind: Deployment
metadata:
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
name: node-deployment
spec:
replicas: 2
selector:
matchLabels:
app: node
template:
metadata:
labels:
app: node
spec:
containers:
- name: node
image:
cloud.canister.io:5000/yourname/imagename
ports:
- containerPort: 3000
imagePullSecrets:
- name: regcred # secret that K8s uses
to access image
---
apiVersion: v1
kind: Service
metadata:
name: node
spec:
selector:
app: node
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
ports:
- port: 80 # expose the service on internal
port 80
targetPort: 3000 # our NodeJS app listens
on port 3000
MySQL database
kind: PersistentVolume
apiVersion: v1
metadata:
name: mysql-pv-volume
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
labels:
type: local
spec:
storageClassName: cinder-high-speed # CHANGE
HERE
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
storageClassName: cinder-high-speed # CHANGE
HERE
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
type: NodePort
ports:
- port: 3306
targetPort: 3306
nodePort: 31306 # exposed port we can
communicate to
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
labels:
app: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: yourR4ndomP455w0rd
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
Days of the paid SSL certificates are luckily gone thanks to Let’s
Encrypt which provides free SSL certificates. But that’s not the
NodeJS app with database over SSL on Kubernetes - Łukasz... about:reader?url=https://medium.com/@lukaszwolnik/nodejs...
apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
name: node-ssl-prod
spec:
acme:
server: https://acme-
v02.api.letsencrypt.org/directory
email: your@email.com # CHANGE TO YOUR
EMAIL HERE
privateKeySecretRef:
name: node-ssl-prod
http01: {}
Grande finale
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: node-ingress
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: node-
ssl-prod
spec:
tls:
- hosts:
- app.yourdomain.com
secretName: node-ssl-prod
rules:
- host: app.yourdomain.com
http:
paths:
- path: /*
backend:
serviceName: lockjs
servicePort: 80 - backend:
serviceName: node
servicePort: 80
Deploy using:
You can now securely access your NodeJS app via HTTPS by
typing https://app.yourdomain.com in a browser.
Conclusion
I believe it was even for a personal project like this. One of the
great consequences of deploying apps on Kubernetes is its
requirement to describe every piece of an infrastructure in a file.
In this tutorial we used the following files: node.yml, mysql-
pv.yml, mysql.yml, prod-issuer.yml and ingress-
node.yml.