Fix: SSL connection to Kubernetes API and make deployment cluster-agnostic
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -159,3 +159,6 @@ kubeconfig
|
||||
|
||||
# Docker
|
||||
.dockerignore
|
||||
|
||||
# MCP
|
||||
.playwright-mcp/
|
||||
@@ -41,11 +41,23 @@ class K8sClient:
|
||||
with open('/var/run/secrets/kubernetes.io/serviceaccount/namespace', 'r') as f:
|
||||
namespace = f.read().strip()
|
||||
|
||||
# Create configuration with token
|
||||
# Create configuration with token and handle SSL properly
|
||||
configuration = client.Configuration()
|
||||
configuration.host = f"https://kubernetes.default.svc"
|
||||
configuration.ssl_ca_cert = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
|
||||
configuration.api_key = {"authorization": f"Bearer {token}"}
|
||||
|
||||
# Try to use CA cert, but disable SSL verification if not available
|
||||
try:
|
||||
with open('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt', 'r') as f:
|
||||
ca_cert = f.read().strip()
|
||||
if ca_cert:
|
||||
configuration.ssl_ca_cert = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
|
||||
configuration.verify_ssl = True
|
||||
else:
|
||||
configuration.verify_ssl = False
|
||||
except:
|
||||
configuration.verify_ssl = False
|
||||
|
||||
client.Configuration.set_default(configuration)
|
||||
|
||||
except FileNotFoundError:
|
||||
|
||||
@@ -24,15 +24,13 @@ spec:
|
||||
app.kubernetes.io/component: governance
|
||||
spec:
|
||||
serviceAccountName: resource-governance-sa
|
||||
imagePullSecrets:
|
||||
- name: docker-hub-secret
|
||||
# imagePullSecrets:
|
||||
# - name: docker-hub-secret
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000940000
|
||||
fsGroup: 1000940000
|
||||
containers:
|
||||
- name: resource-governance
|
||||
image: andersonid/openshift-resource-governance:latest
|
||||
image: andersonid/resource-governance:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
|
||||
Reference in New Issue
Block a user