How to secure applications running on Kubernetes (SSL/TLS Certificates)?

Securing an application running on Kubernetes (SSL/TLS Certificates)

Create TLS Secret:

Using kubectl:$ kubectl create secret tls my-tls-secret \
--key < private key filename> \
--cert < certificate filename>
--- 
apiVersion: v1
data:
tls.crt: "base64 encoded cert"
tls.key: "base64 encoded key"
kind: Secret
metadata:
name: my-tls-secret
namespace: default
type: kubernetes.io/tls

Ingress with TLS:

--- 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tls-example-ingress
spec:
rules:
-
host: mydomain.com
http:
paths:
-
backend:
serviceName: my-service
servicePort: 80
path: /
tls:
-
hosts:
- mydomain.com
secretName: my-tls-secret

Self Signed Certificate

$ OpenSSL genrsa -out ca.key 2048
$ openssl req -x509 \
-new -nodes \
-days 365 \
-key ca.key \
-out ca.crt \
-subj "/CN=yourdomain.com"
$ kubectl create secret tls my-tls-secret \
--key ca.key \
--cert ca.crt
secret "my-tls-secret" created
$ kubectl get secrets/my-tls-secretNAME            TYPE                DATA      AGEmy-tls-secret   kubernetes.io/tls   2         37s
$ kubectl describe secrets/my-tls-secret
Name: my-tls-secret
Namespace: default
Labels:
Annotations:
Type: kubernetes.io/tlsData
====
tls.crt: 1115 bytes
tls.key: 1675 bytes

How to do TLS between microservices in Kubernetes?

$ kubectl describe service/grpcserver
Name: grpcserver
Namespace: default
Labels: app=grpcserver
Annotations: <none>
Selector: app=grpcserver
Type: ClusterIP
IP: 10.108.125.158
Port: 8000 8000/TCP
TargetPort: 8000/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
grpcserver
grpcserver.default.svc
grpcserver.default.svc.cluster.local
10.108.125.158
generate the client certificate with cfssl
kubectl create secret tls server — cert=server.pem — key=server.key
kubectl create secret tls client — cert=client.pem — key=client.key
https://avmconsulting.net/

--

--

AVM Consulting — Clear strategy for your cloud

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kubernetes Advocate

Vineet Sharma-Founder and CEO of Kubernetes Advocate Tech author, cloud-native architect, and startup advisor.https://in.linkedin.com/in/vineet-sharma-0164