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
|
# Docker
|
||||||
.dockerignore
|
.dockerignore
|
||||||
|
|
||||||
|
# MCP
|
||||||
|
.playwright-mcp/
|
||||||
@@ -41,11 +41,23 @@ class K8sClient:
|
|||||||
with open('/var/run/secrets/kubernetes.io/serviceaccount/namespace', 'r') as f:
|
with open('/var/run/secrets/kubernetes.io/serviceaccount/namespace', 'r') as f:
|
||||||
namespace = f.read().strip()
|
namespace = f.read().strip()
|
||||||
|
|
||||||
# Create configuration with token
|
# Create configuration with token and handle SSL properly
|
||||||
configuration = client.Configuration()
|
configuration = client.Configuration()
|
||||||
configuration.host = f"https://kubernetes.default.svc"
|
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}"}
|
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)
|
client.Configuration.set_default(configuration)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|||||||
@@ -24,15 +24,13 @@ spec:
|
|||||||
app.kubernetes.io/component: governance
|
app.kubernetes.io/component: governance
|
||||||
spec:
|
spec:
|
||||||
serviceAccountName: resource-governance-sa
|
serviceAccountName: resource-governance-sa
|
||||||
imagePullSecrets:
|
# imagePullSecrets:
|
||||||
- name: docker-hub-secret
|
# - name: docker-hub-secret
|
||||||
securityContext:
|
securityContext:
|
||||||
runAsNonRoot: true
|
runAsNonRoot: true
|
||||||
runAsUser: 1000940000
|
|
||||||
fsGroup: 1000940000
|
|
||||||
containers:
|
containers:
|
||||||
- name: resource-governance
|
- name: resource-governance
|
||||||
image: andersonid/openshift-resource-governance:latest
|
image: andersonid/resource-governance:latest
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|||||||
Reference in New Issue
Block a user