Skip to content

Commit c5921c0

Browse files
committedApr 16, 2019
first commit
0 parents  commit c5921c0

7 files changed

+206
-0
lines changed
 

‎README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Kubernetes SSL Ingress and Service Deployment Setup on GCP
2+
3+
A simple k8s project that demonstrates how to set up a web service, route traffic to it via a load balancer and configure the load balancer to use SSL certificates.
4+
5+
1 - create container cluster. can also be done via gcp console.
6+
7+
```
8+
gcloud container clusters create <cluster-name> --zone <zone-name> --machine-type g1-small --num-nodes 1
9+
```
10+
11+
2 - retrieve cluster credentials if needed.
12+
13+
```
14+
gcloud container clusters get-credentials <cluster-name>
15+
```
16+
17+
3 - deploy the application.
18+
19+
```
20+
kubectl run <deployment-name> --image=gcr.io/google-samples/hello-app:1.0 --port=8080
21+
```
22+
23+
4 - expose deployment as internal service. This will not make the application public yet.
24+
25+
```
26+
kubectl expose deployment <deployment-name> --target-port=8080 --type=NodePort
27+
28+
or
29+
30+
kubectl apply -f deployment.yaml
31+
```
32+
33+
5 - create a service for the pods created by the deployment during step 4.
34+
35+
```
36+
kubectl apply -f service.yaml
37+
```
38+
39+
6 - create an SSL certificate and a set of keys.
40+
41+
```
42+
// key
43+
openssl genrsa -out test-ingress.key 2048
44+
45+
// signing request
46+
openssl req -new -key test-ingress.key -out test-ingress.csr \
47+
-subj "/CN=k8s.shapes.ai"
48+
49+
// certificate
50+
openssl x509 -req -days 365 -in test-ingress.csr -signkey test-ingress.key \
51+
-out test-ingress.crt
52+
```
53+
54+
7a - Create a secret for holding certificate and key.
55+
56+
```
57+
kubectl create secret tls my-secret \
58+
--cert test-ingress.crt --key test-ingress.key
59+
```
60+
61+
7b - create ingress resource to generate a load balancer that will route traffic to the application and deploy it. In the ingress manifest specify to use the certificate generated in the previous step.
62+
63+
```
64+
kubectl apply -f ingress.yaml
65+
```
66+
67+
8a - [optional] define a static IP for the application. To use a static IP using Ingress the following conditions must be met:
68+
69+
- A Service with `type:NodePort`
70+
- An Ingress configured with the service name and static IP annotation
71+
- Global IP addresses only work with Ingress resource type
72+
73+
```
74+
gcloud compute addresses create <static-ip-name> --global
75+
```
76+
77+
8b - [optional] configure the existing Ingress resource to use the reserved IP address. See ingress.yaml > metadata.annotations.
78+
79+
8c - [optional] edit the domain dns A Record to point to the global static IP address.
80+
81+
NOTE: see https://cloud.google.com/load-balancing/docs/ssl-certificates#create-managed-ssl-cert-resource for instructions about how to set up a certificate signed by google.
82+
To retrive the ingress proxy name run `gcloud compute target-https-proxies list`.
83+
84+
9 - [optional] clean up.
85+
86+
```
87+
kubectl delete ingress <ingress-name>
88+
89+
gcloud compute addresses delete <static-ip-name> --global
90+
91+
gcloud container clusters delete <cluster-name>
92+
```
93+
94+
## Useful links:
95+
96+
- https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip
97+
- https://cloud.google.com/load-balancing/docs/ssl-certificates
98+
- https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-multi-ssl

‎deployment.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: my-deployment
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: test-app
9+
replicas: 3
10+
template:
11+
metadata:
12+
labels:
13+
app: test-app
14+
spec:
15+
containers:
16+
- name: hello
17+
image: "gcr.io/google-samples/hello-app:2.0"
18+
env:
19+
- name: "PORT"
20+
value: "5001"

‎ingress.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: my-ingress
5+
annotations:
6+
kubernetes.io/ingress.global-static-ip-name: k8s-test-static-ip
7+
spec:
8+
tls:
9+
- secretName: my-first-secret
10+
rules:
11+
- host: k8s.shapes.ai
12+
http:
13+
paths:
14+
- backend:
15+
serviceName: my-service
16+
servicePort: first-port

‎service.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: my-service
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: test-app
9+
ports:
10+
- name: first-port
11+
protocol: TCP
12+
port: 6001
13+
targetPort: 5001

‎test-ingress.crt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICrDCCAZQCCQCr9S0pWKdR8jANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1r
3+
OHMuc2hhcGVzLmFpMB4XDTE5MDQwMjEwNDIxM1oXDTIwMDQwMTEwNDIxM1owGDEW
4+
MBQGA1UEAwwNazhzLnNoYXBlcy5haTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
5+
AQoCggEBANdrRdbzCcaLcJE7CcZPR3JeoyJiPAuM1l3U4Dc7fn2637Cz7WdYoMa9
6+
3fdTGWMj8w8CtyGAIyA9wIyinqbn5O3F7kVw+m1gQkF97HdOuymHI6AycDTs5DH1
7+
gVOdlgQPYrsxV+fksWvnBCQiTZMY0EHMf2GUJDxJX0F0q2bVkxf8XoCOswcrt98X
8+
xsllEe/04NBSt9b/GIOTv6FpwJPKXr4uuZ7GFUDic0K4uCjr2cQr8uROWVctQnsN
9+
PnGXP+9Z18Ls+I0ryHzMyOb+RT1K6HV1pDX+XL2YKEDlHUnpI32owwD+u0GM7nyi
10+
I5ohAykFyw6Lil6AUOzpTCX/Ao/FzO8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA
11+
SvrjOOCK4vD/Hf0PvKViaSMG5zke02AiruCpm9Z7m8VSWhqV6wsyaFQKTnHN2cXT
12+
oatUmzmbc1Sh1qchh4xSWm1FAtoauTsmMmszB+3boY81P+Sla9OFfu37Isq6S9pb
13+
lIufasEtqdcP92SvsYfN3543QDtCkHAGQUzhWGWMUUwrDykuFoJAhBGMDJ99cpQ3
14+
Wt5y7ozxQRvhX8g9Kcyc9QpCsPEPfi0qMHu7YGu14KApuxR2ugvI8CEQZj9dRT/6
15+
tvzjHV17ux/deFcdGaAYDUW3fgELyBjvmfrg6bTkOr7rZKib+hsn36qAQu/KTdEl
16+
RQ5yP+aGW32xuwv3qIajAA==
17+
-----END CERTIFICATE-----

‎test-ingress.csr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIICXTCCAUUCAQAwGDEWMBQGA1UEAwwNazhzLnNoYXBlcy5haTCCASIwDQYJKoZI
3+
hvcNAQEBBQADggEPADCCAQoCggEBANdrRdbzCcaLcJE7CcZPR3JeoyJiPAuM1l3U
4+
4Dc7fn2637Cz7WdYoMa93fdTGWMj8w8CtyGAIyA9wIyinqbn5O3F7kVw+m1gQkF9
5+
7HdOuymHI6AycDTs5DH1gVOdlgQPYrsxV+fksWvnBCQiTZMY0EHMf2GUJDxJX0F0
6+
q2bVkxf8XoCOswcrt98XxsllEe/04NBSt9b/GIOTv6FpwJPKXr4uuZ7GFUDic0K4
7+
uCjr2cQr8uROWVctQnsNPnGXP+9Z18Ls+I0ryHzMyOb+RT1K6HV1pDX+XL2YKEDl
8+
HUnpI32owwD+u0GM7nyiI5ohAykFyw6Lil6AUOzpTCX/Ao/FzO8CAwEAAaAAMA0G
9+
CSqGSIb3DQEBCwUAA4IBAQAwJoNkrW8T/myKpKiqm6kTlegOnUfuZHNmzPtKkpn/
10+
ZziNY/CJMCa4clq64aUz9q4G8e9ixow8frQie9ikTtjGqrGawO/DnTQt9fJ6wJ+c
11+
xpU2Qrxp1gyi7Yk46+9top54aMIvcsBdkz4k3SEjhefR1xWIIinGMhO/P7H/BPL/
12+
ZderUuXCIWR4avwrfrn27r7lIMUJcLDoTmwQW7g2R20s5nh1WoJt63gt+P/ud4pv
13+
ooSl6leb9e6elP1H2o/268b/flDee8UJri2K6qhP3dXAhksNQEDXvOsTWFLu2Rlf
14+
OCWRd2VBeTQeF2rclog4QQYptFQi6wAFxC/0SSUKMzPN
15+
-----END CERTIFICATE REQUEST-----

‎test-ingress.key

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpgIBAAKCAQEA12tF1vMJxotwkTsJxk9Hcl6jImI8C4zWXdTgNzt+fbrfsLPt
3+
Z1igxr3d91MZYyPzDwK3IYAjID3AjKKepufk7cXuRXD6bWBCQX3sd067KYcjoDJw
4+
NOzkMfWBU52WBA9iuzFX5+Sxa+cEJCJNkxjQQcx/YZQkPElfQXSrZtWTF/xegI6z
5+
Byu33xfGyWUR7/Tg0FK31v8Yg5O/oWnAk8pevi65nsYVQOJzQri4KOvZxCvy5E5Z
6+
Vy1Cew0+cZc/71nXwuz4jSvIfMzI5v5FPUrodXWkNf5cvZgoQOUdSekjfajDAP67
7+
QYzufKIjmiEDKQXLDouKXoBQ7OlMJf8Cj8XM7wIDAQABAoIBAQC+MQH6Y53v49DB
8+
CMT6h6hm+9NAWkb1U6U4Nui3Gxn02/b/RfyG0CMzFRNSd9XkSCsix5z0QPPCVYMZ
9+
J8K3Teo7XBOgz7zqsKAOvqT2OVbZtWzo1V9n+vcGfOFv96QpdYQQDeK05J8Yy2BG
10+
ntqq0q+cSHb2qhrL92PYoK9sHYi/FP0z1p3EKyrgkJRuRSbBbkM7r8LCIguMe9j4
11+
5g0wp7xWaYsfbkz2WS+RQB3hFNbaAEly7u7n+UalKRQyj0iqr5x/pRXStsptMTIs
12+
nBamEXWaiEe7pduits1DhDCZDioFDaKQ0D63CeMUgaVS42Y3JuTvrxo1tkwOgHEr
13+
+PewA0cBAoGBAPUt2ApuRdVCgPO2pnQH/jqJR3NHSd7WDmlnUITw8TLEnivA2yLM
14+
vInI9D9TIoP/JsAQOG8wMB1FfKl3BJpqWoFRIvWKcP/3EK4/ZXeywmejt8tSGaBn
15+
v6CLIyB+ucvfNtqlsUBicUOP1vwmnMtV523wQz6nrYOeVebwTmyy9dbBAoGBAODt
16+
L11YTsExCU3GB1thJB6nlk31hpFdkTSLtH2k04omeNeExTAtz0H1yplgBozbhrWt
17+
P0qmzDx2JvepEf/mUEMYhp90m+D4pRdzy7ij1LxV1ahh3VLdqWJ5N8DmjOcsguqa
18+
Ky0GO+3mCfHez9euiI5OKYeNzIU9ddVfjVV7/r+vAoGBAIhGuf1aO7CErX5JOI3n
19+
33QT18YIitO0MQB/L28lKTups6zoHiVinS0MqE4GXHn3uUcp/OQ4aZXriJX9FG7r
20+
zHByc7b9A0ASyI/Bpxl4H7xRcJgvgxT4dbe7foPSTF04LZosXLBHx2LhMYKnx6Dx
21+
l5gw4n+R3cz5lg+t5Dlg42pBAoGBAJ+Et3W9HkV3UIDe8/LDxwkSk8+AVMqdkFCy
22+
z/PXxMsSk9tNZ0fPBVFjTydNaffV7QjF8MAx4WDz7pjwSDqzjbK4HynRWofH79Xd
23+
Its1HbfgLCI6HewaFnonO/pLyBxffg2B/yL0a+ZBokXuXns5ZdF+74cacrUALKSC
24+
GstIoBgzAoGBAIr7LON95hjWdUjkeDX81WBoT9xT7SD+xXrrvHdhnGikAZiDRYRO
25+
I4fb7zrFflJ2x6verZgQ5T94HTOnNEbu7E3/UTwh9x1FslPSAa+z0lc4e8xZcSWE
26+
Rtf5xkeUD+Q9woE3pWUsKlabPgCu9fzK4VwWL9pJWW4FyAqzqloil6xb
27+
-----END RSA PRIVATE KEY-----

0 commit comments

Comments
 (0)
Please sign in to comment.