[ADD] Added k8ssalt
This commit is contained in:
parent
0fc89eb375
commit
37de58ae74
74
deploySalt.sh
Executable file
74
deploySalt.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
applySed=0
|
||||
|
||||
checkReplicas() {
|
||||
if [[ "$1" == "-r" ]]; then
|
||||
shift
|
||||
if [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
replicas="$1"
|
||||
applySed=1
|
||||
else
|
||||
echo "Error: Invalid REPLICAS value. Please provide a positive integer."
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
else
|
||||
replicas=1
|
||||
fi
|
||||
}
|
||||
|
||||
applySaltMinion() {
|
||||
if [ "$applySed" -eq 1 ]; then
|
||||
echo "Applying Salt-minion yaml with $replicas replicas..."
|
||||
sed "s/replicas:.*/replicas: $replicas/" salt-minion.yaml | kubectl apply -f -
|
||||
else
|
||||
echo "Applying Salt-minion yaml..."
|
||||
kubectl apply -f salt-minion.yaml
|
||||
fi
|
||||
}
|
||||
|
||||
deleteSalt() {
|
||||
echo "Deleting Salt infrastructure..."
|
||||
kubectl delete -f salt-minion.yaml
|
||||
kubectl delete -f salt-master.yaml
|
||||
echo "Salt infrastructure deleted."
|
||||
}
|
||||
|
||||
waitUntilSaltMasterInitialized() {
|
||||
attempts=0
|
||||
max_attempts=10
|
||||
while [ "$attempts" -lt "$max_attempts" ]; do
|
||||
echo "Checking if Salt-master has initialized..."
|
||||
sleep 5
|
||||
if kubectl exec "$saltmaster" -it -- /bin/sh -c "salt-key -L" | grep -q "minion"; then
|
||||
echo "Salt-master is up and running. Accepting minion keys..."
|
||||
kubectl exec "$saltmaster" -it -- /bin/sh -c "salt-key -A -y"
|
||||
break
|
||||
fi
|
||||
((attempts++))
|
||||
done
|
||||
}
|
||||
|
||||
deploySalt() {
|
||||
if [[ "$1" == "-d" ]]; then
|
||||
deleteSalt
|
||||
else
|
||||
checkReplicas "$@"
|
||||
applySaltMinion
|
||||
|
||||
echo "Applying Salt-master yaml..."
|
||||
kubectl apply -f salt-master.yaml
|
||||
|
||||
echo "Checking for Salt-master pod name..."
|
||||
saltmaster=$(kubectl get pods | grep salt-master | cut -d ' ' -f 1)
|
||||
kubectl wait --for=condition=Ready "pod/$saltmaster" --timeout=300s
|
||||
|
||||
waitUntilSaltMasterInitialized
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
clear
|
||||
# Call the main function
|
||||
deploySalt "$@"
|
||||
72
salt-master.yaml
Normal file
72
salt-master.yaml
Normal file
@ -0,0 +1,72 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: salt-master
|
||||
namespace: webserver
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: salt
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: salt
|
||||
spec:
|
||||
containers:
|
||||
- name: salt
|
||||
image: saltstack/salt
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: salt-master-config
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: salt-master-config
|
||||
namespace: webserver
|
||||
data:
|
||||
SALT_API_CONFIG: |
|
||||
{
|
||||
"rest_cherrypy": {
|
||||
"port": 8000,
|
||||
"ssl_crt": "/etc/pki/tls/certs/localhost.crt",
|
||||
"ssl_key": "/etc/pki/tls/certs/localhost.key"
|
||||
},
|
||||
"external_auth": {
|
||||
"sharedsecret": {
|
||||
"salt": [
|
||||
".*",
|
||||
"@wheel",
|
||||
"@jobs",
|
||||
"@runner"
|
||||
]
|
||||
}
|
||||
},
|
||||
"sharedsecret": "saFGGAIGJitwajisajT612QTjq3ifap14"
|
||||
}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: salt-master-service
|
||||
namespace: webserver
|
||||
spec:
|
||||
selector:
|
||||
app: salt # Select the Pods based on their labels (should match the Deployment labels)
|
||||
ports:
|
||||
- name: rest
|
||||
protocol: TCP
|
||||
port: 8000 # Port for REST API
|
||||
targetPort: 8000 # Port on the container to which REST API traffic will be forwarded
|
||||
- name: minion
|
||||
protocol: TCP
|
||||
port: 4505 # Port for Salt Minion
|
||||
targetPort: 4505 # Port on the container to which Salt Minion traffic will be forwarded
|
||||
- name: master
|
||||
protocol: TCP
|
||||
port: 4506 # Port for Salt Master
|
||||
targetPort: 4506 # Port on the container to which Salt Master traffic will be forwarded
|
||||
type: ClusterIP # This creates an internal ClusterIP Service
|
||||
clusterIP: 10.43.14.232
|
||||
37
salt-minion.yaml
Normal file
37
salt-minion.yaml
Normal file
@ -0,0 +1,37 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: salt-minion
|
||||
namespace: webserver
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: salt-miniondev
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: salt-miniondev
|
||||
spec:
|
||||
volumes:
|
||||
- name: salt-miniondev-config
|
||||
configMap:
|
||||
name: salt-miniondev-config
|
||||
containers:
|
||||
- name: salt-miniondev
|
||||
image: saltstack/salt
|
||||
command: ["/bin/sh", "-c"]
|
||||
args: ["salt-minion"]
|
||||
volumeMounts:
|
||||
- name: salt-miniondev-config
|
||||
mountPath: /etc/salt/minion.d
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: salt-miniondev-config
|
||||
namespace: webserver
|
||||
data:
|
||||
default.conf: |
|
||||
master: 10.43.14.232
|
||||
76
salt-multiregion-master-dev.yaml
Normal file
76
salt-multiregion-master-dev.yaml
Normal file
@ -0,0 +1,76 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: salt-master
|
||||
namespace: webserver
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: salt
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: salt
|
||||
spec:
|
||||
containers:
|
||||
- name: salt
|
||||
image: saltstack/salt
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: salt-master-config
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: salt-master-config
|
||||
namespace: webserver
|
||||
data:
|
||||
SALT_API_CONFIG: |
|
||||
{
|
||||
"rest_cherrypy": {
|
||||
"port": 8000,
|
||||
"ssl_crt": "/etc/pki/tls/certs/localhost.crt",
|
||||
"ssl_key": "/etc/pki/tls/certs/localhost.key"
|
||||
},
|
||||
"external_auth": {
|
||||
"sharedsecret": {
|
||||
"salt": [
|
||||
".*",
|
||||
"@wheel",
|
||||
"@jobs",
|
||||
"@runner"
|
||||
]
|
||||
}
|
||||
},
|
||||
"sharedsecret": "saFGGAIGJitwajisajT612QTjq3ifap14"
|
||||
}
|
||||
master.conf: |
|
||||
{
|
||||
"auto_accept": True
|
||||
}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: salt-master-service
|
||||
namespace: webserver
|
||||
spec:
|
||||
selector:
|
||||
app: salt # Select the Pods based on their labels (should match the Deployment labels)
|
||||
ports:
|
||||
- name: rest
|
||||
protocol: TCP
|
||||
port: 8000 # Port for REST API
|
||||
targetPort: 8000 # Port on the container to which REST API traffic will be forwarded
|
||||
- name: minion
|
||||
protocol: TCP
|
||||
port: 4505 # Port for Salt Minion
|
||||
targetPort: 4505 # Port on the container to which Salt Minion traffic will be forwarded
|
||||
- name: master
|
||||
protocol: TCP
|
||||
port: 4506 # Port for Salt Master
|
||||
targetPort: 4506 # Port on the container to which Salt Master traffic will be forwarded
|
||||
type: ClusterIP # This creates an internal ClusterIP Service
|
||||
clusterIP: 10.43.14.232
|
||||
Loading…
x
Reference in New Issue
Block a user