3.4 KiB
3.4 KiB
Exercise: jafner.dev on GKE
Cert-Manager - Deploy cert-manager on Google Kubernetes Engine
Setting Up Initial Services
- Create cluster
gcloud container clusters create jafner-dev --preemptible --num-nodes=3
This cluster is preemptible, which means it's basically for testing and will kill itself within 24 hours. This command will take a few minutes to create the cluster. - Create the example hello and hello2 deployments:
kubectl apply -f ./hello/Deployment.yaml -f ./hello2/Deployment.yaml
- Create the example hello and hello2 internal services:
kubectl apply -f ./hello/Service.yaml -f ./hello2/Service.yaml
- Create a public global static IP for the cluster to use:
gcloud compute addresses create web-ip --global
This step is applied across the GCP project and is not necessary for a new cluster. - Open Google Domains for jafner.dev and ensure the A records for
*.jafner.dev
andjafner.dev
are pointed at the correct IP address. - Create the Ingress without TLS:
kubectl apply -f ./Ingress-noTLS.yaml
Once this ingress is created, the services should be internet accessible by domain name. Trycurl http://hello.jafner.dev
andcurl http://hello2.jafner.dev
. - Install cert-manager:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cert-manager.yaml
(We use the generic merged manifest here). After this is done, you can usekubectl explain
for the new CustomResourceDefinitionsCertificate
,CertificateRequest
, andIssuer
, which are installed with Cert-manager. - Create staging and production Issuers for LetsEncrypt:
kubectl apply -f ./cert-manager/Issuer.yaml
- Create empty secret for storing SSL certificate:
kubectl apply -f ./cert-manager/Secret.yaml
- Apply the Ingress with TLS configured with the staging issuer:
kubectl apply -f Ingress-staging.yaml
It will take several minutes for the background process of acquiring and loading the certificate to complete. You can check on the process withcurl -v --insecure https://hello.jafner.dev
. While the process is running, you will get an error code 35 withSSL_ERROR_SYSCALL
. Once the process is complete, curl will return verbose certificate information and the "Hello, world!" message from the server. - Apply the Ingress with TLS configured with the production issuer:
kubectl apply -f Ingress.yaml
This process will take several minutes like the previous one. Once it is complete, you should be able to accesshttps://hello.jafner.dev
andhttps://hello2.jafner.dev
by browser.
Adding A New Service: dndtools
- Deploy the new service:
kubectl apply -f ./dndtools/Deployment.yaml -f ./dndtools/Service.yaml
- Edit
Ingress.yaml
to configure the new application.- Add the new host to
spec.tls.hosts
(e.g. 5e.jafner.dev). - Add a stanza to
spec.rules
for the new host. For example:
- Add the new host to
spec:
rules:
- host: "5e.jafner.dev"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: dndtools
port:
number: 80
- Apply the edited
Ingress.yaml
:kubectl apply -f Ingress.yaml
and wait for the changes to apply. Once changes are applied, the new service will be accessible in the browser athttps://5e.jafner.dev
.
Done!