This guide describes the steps required to to recreate the bug decribed here.
This was tested on a cluster using Tanzu Application Platform 1.3.0.
You will need:
- A Kubernetes cluster with Knative installed and DNS configured. See Install Knative Serving.
- Knative Serving should have Auto-TLS enabled. See Using Auto TLS.
- Optional: Docker installed and running on your local machine, and a Docker Hub account configured.
- Optional: You can use the Knative CLI client
knto simplify resource creation and deployment. Alternatively, you can usekubectlto apply resource files directly.
The latest version of this repository exists at docker.io/spines83/helloworld-go.
If you want to make changes and build the sample code into a container, and push using Docker Hub, enter the following commands and replace {username} with your Docker Hub username:
# Build the container on your local machine
docker build -t {username}/helloworld-go .
# Push the container to docker registry
docker push {username}/helloworld-goAfter the build has completed and the container is pushed to docker hub, you can deploy the app into your cluster. Choose one of the following methods:
Apply the configuration using kubectl:
kubectl apply -f deploy/service.yamlRun the following command to find the domain URL for your service:
kubectl get ksvc helloworld-go --output=custom-columns=NAME:.metadata.name,URL:.status.urlExample:
NAME URL
helloworld-go https://helloworld-go.default.<DOMAIN>NOTE: This should be an https endpoint. If it is not, make sure Auto-TLS is enabled.
You'll need to provide a kubernetes tls certificate in order for the Domain Mapping to create a https endpoint. Make sure you update the domain in the appropriate yamls before applying them.
kubectl apply -f deploy/domainmapping.yaml
# If you have cert manager installed
kubectl apply -f deploy/certificate.yaml
# Otherwise
kubectl create secret tls helloworld-go-dm --cert=path/to/cert/file --key=path/to/key/fileRun the following command to find the domain URL for your service:
kubectl get domainmappingExample:
NAME URL
helloworld-go-dm.default.<DOMAIN> https://helloworld-go-dm.default.<DOMAIN> This should also be HTTPS if we configured the domain mapping with TLS.
Create DNS entries for the above two FQDNs and drop the URL in the browser of your choice. It should respond back with the request headers.
On helloworld-go (Auto TLS), you should see "X-Forwarded-Proto":["https"]. This is the correct behavior.
On helloworld-go-dm (DomainMapping), you should see "X-Forwarded-Proto":["http"]. This is incorrect and should be "https" instead.
These headers are also logged in the container if that's easier to follow.
To remove the sample app from your cluster, delete the service record and corresponding domain mapping:
kubectl delete -f deploy/service.yaml
kubectl delete -f deploy/domainmapping.yaml