spire-demo/
├── README.md
├── go.mod
├── go.sum
├── setup-spire.sh
├── build.sh
├── deployment.yaml
├── proto/
│ ├── echo.proto
│ ├── echo.pb.go
│ └── echo_grpc.pb.go
├── server/
│ ├── main.go
│ └── Dockerfile
└── client/
├── main.go
└── Dockerfile
# Create project directory
mkdir -p spire-demo && cd spire-demo
# Initialize Go module
go mod init spire-demo
# Install necessary tools
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Add to PATH (if not already)
export PATH="$PATH:$(go env GOPATH)/bin"Create a file at proto/echo.proto with the code provided later.
# Create proto directory (if not already)
mkdir -p proto
# Generate Go code
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/echo.proto
# Download dependencies
go mod tidyCreate the following files using the full code provided below:
server/main.goserver/Dockerfileclient/main.goclient/Dockerfiledeployment.yamlsetup-spire.shbuild.sh
chmod +x setup-spire.sh build.shminikube status
# If not running, start it
minikube start# If SPIRE was previously installed, uninstall it first
helm uninstall spire -n spire-system 2>/dev/null || true
kubectl delete namespace spire-system 2>/dev/null || true
# Wait for cleanup to complete
sleep 10./setup-spire.shThis script will:
- Install SPIRE via Helm and set the trust domain to
supasaf.com - Wait for SPIRE components to become ready
- Create dedicated Service Accounts
- Register node identity (
spiffe://supasaf.com/minikube-node) - Register server identity (using Service Account selector)
- Register client identity (using Service Account selector)
./build.shkubectl apply -f deployment.yaml# Check pod status
kubectl get pods
# View server logs
kubectl logs -l app=my-server -f
# In another terminal, view client logs
kubectl logs -l app=my-client -fServer Logs:
ss@ss:~/spire-demo$ kubectl logs -l app=my-server -f
2025/10/06 08:51:24 🚀 Starting server, waiting for SPIRE agent...
2025/10/06 08:51:25 ✅ Successfully connected to SPIRE agent
2025/10/06 08:51:25 🎧 Server listening on :8080 with mTLS enabled
2025/10/06 08:51:25 ✅ Received a request from client with SPIFFE ID: spiffe://supasaf.com/client
2025/10/06 08:51:31 ✅ Received a request from client with SPIFFE ID: spiffe://supasaf.com/client
2025/10/06 08:51:50 ✅ Received a request from client with SPIFFE ID: spiffe://supasaf.com/client
Client Logs:
ss@ss:~/spire-demo$ kubectl logs -l app=my-client -f
2025/10/06 08:51:30 🚀 Starting client, waiting for SPIRE agent...
2025/10/06 08:51:31 ✅ Successfully connected to SPIRE agent
2025/10/06 08:51:31 🔄 Attempting to connect to server (attempt 1/10)...
2025/10/06 08:51:31 ✅ Connected to server
2025/10/06 08:51:31 📤 Sending request to server...
2025/10/06 08:51:31 ✅ Response from server: Hello SPIFFE from spiffe://supasaf.com/client
2025/10/06 08:51:31 🎉 Zero Trust communication successful!
To reset the environment:
# Delete application deployment
kubectl delete -f deployment.yaml
# Uninstall SPIRE
helm uninstall spire -n spire-system
# Optional: delete the namespace
kubectl delete namespace spire-system