Commit bd451927 authored by Santhosh Kumar's avatar Santhosh Kumar

my updates

parent dfcad3a4
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/invoke', methods=['POST'])
def invoke_function():
# Parse request data
data = request.json
# Extract parameters or payload from the request
param1 = data.get('param1')
param2 = data.get('param2')
# Call your deployed function with the provided parameters
result = your_deployed_function(param1, param2)
# Prepare response
response = {
"result": result
}
return jsonify(response)
def your_deployed_function(param1, param2):
# Your logic to process the parameters and perform some computation
# This function represents your deployed function
return param1 + param2
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
# Use an official Python runtime as a parent image
FROM python:3.8-slim
# Set the working directory in the container
WORKDIR /app
# Copy the Flask application code into the container
COPY . .
# Install any dependencies needed for your Flask application
RUN pip install Flask
# Define the command to run the Flask application
CMD ["python", "app.py"]
apiVersion: v1
kind: Service
metadata:
name: your-service
spec:
selector:
app: example1-service
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/invoke', methods=['POST'])
def invoke_function():
# Parse request data
data = request.json
# Extract parameters or payload from the request
param1 = data.get('param1')
param2 = data.get('param2')
# Call your deployed function with the provided parameters
result = your_deployed_function(param1, param2)
# Prepare response
response = {
"result": result
}
return jsonify(response)
def your_deployed_function(param1, param2):
# Your logic to process the parameters and perform some computation
# This function represents your deployed function
return param1 + param2
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
docker build -t your-image-name .
docker push your-image-name
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f hpa.yaml
# metrics
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# edit/modify
kubectl get hpa <hpa_name> -o yaml > hpa.yaml
kubectl apply -f hpa.yaml
or
kubectl edit hpa <hpa_name>
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-view: "true"
name: system:aggregated-metrics-reader
rules:
- apiGroups:
- metrics.k8s.io
resources:
- pods
- nodes
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- nodes/metrics
verbs:
- get
- apiGroups:
- ""
resources:
- pods
- nodes
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: https
selector:
k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
selector:
matchLabels:
k8s-app: metrics-server
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
k8s-app: metrics-server
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=10250
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-use-node-status-port
- --metric-resolution=15s
image: registry.k8s.io/metrics-server/metrics-server:v0.7.1
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /livez
port: https
scheme: HTTPS
periodSeconds: 10
name: metrics-server
ports:
- containerPort: 10250
name: https
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /readyz
port: https
scheme: HTTPS
initialDelaySeconds: 20
periodSeconds: 10
resources:
requests:
cpu: 100m
memory: 200Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /tmp
name: tmp-dir
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: metrics-server
volumes:
- emptyDir: {}
name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
labels:
k8s-app: metrics-server
name: v1beta1.metrics.k8s.io
spec:
group: metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: metrics-server
namespace: kube-system
version: v1beta1
versionPriority: 100
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-deployment
spec:
replicas: 1
selector:
matchLabels:
app: your-app
template:
metadata:
labels:
app: your-app
spec:
containers:
- name: your-container
image: msanth/your-image-name
ports:
- containerPort: 8080
resources:
requests:
memory: "256Mi"
cpu: "0.5"
limits:
memory: "512Mi"
cpu: "1"
# Define autoscaling behavior using annotations
#annotations:
# autoscaling.knative.dev/target: "70"
# autoscaling.knative.dev/metric: "cpu" # can be concurrency and rps (rates per second)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-deployment
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple-fanout-example
spec:
rules:
- host: cs695
http:
paths:
- path: /foo
pathType: Prefix
backend:
service:
name: service1
port:
number: 4200
- path: /bar
pathType: Prefix
backend:
service:
name: your-service
port:
number: 80
import curses
def main():
screen = curses.initscr()
curses.start_color()
curses.noecho()
curses.cbreak()
screen.keypad(True)
# Set colors
black = curses.color_pair(1)
red = curses.color_pair(2)
green = curses.color_pair(3)
while True:
# Clear the screen
screen.clear()
# Display information in first row
screen.addstr(0, 0, "INFO: " + black("Field Info"))
screen.refresh()
# Split second row into two columns
screen.addstr(1, 0, "Col 1: " + black("Functions"))
screen.addstr(2, 0, "Col 2: " + black("WIP Actions"))
screen.addstr(3, 0, "Col 2: " + black("Failed Actions"))
# Split third row for Grafanna metrics
screen.addstr(4, 0, "Col 1: " + green("Metric 1"))
screen.addstr(5, 0, "Col 2: " + green("Metric 2"))
# Last row for user commands
screen.addstr(6, 0, "Commands: " + red("Command 1"))
# Display the user interface and handle input
curses.wbeginnen(2); curses.winsch([[2]]);
curses.wgetnstr(2,1);
while True:
# Update information in first row
screen.addstr(0, 20, black("Current Date"))
screen.refresh()
# Handle user input
key = screen.getkey()
if key == ord('q'):
break
curses.endwin()
if __name__ == "__main__":
main()
from kubernetes import client, config
from kubernetes.client import configuration
import time
def get_deployment_metrics():
configuration.assert_hostname = False
config.load_kube_config() # Load Kubernetes configuration from default location
configuration.assert_hostname = False
api_instance = client.CustomObjectsApi()
# Retrieve metrics of all deployments in the "default" namespace
deployments_metrics = api_instance.list_namespaced_custom_object(
group="metrics.k8s.io",
version="v1beta1",
namespace="default",
plural="deployments"
)
deployment_metrics_info = []
for deployment in deployments_metrics["items"]:
deployment_name = deployment["metadata"]["name"]
replicas = deployment["spec"]["replicas"]
ready_replicas = deployment["status"]["readyReplicas"]
unavailable_replicas = replicas - ready_replicas if ready_replicas is not None else 0
deployment_metrics_info.append((deployment_name, replicas, ready_replicas, unavailable_replicas))
return deployment_metrics_info
def display_dashboard(deployment_metrics_info):
print("Deployment Name\tReplicas\tReady Replicas\tUnavailable Replicas")
print("-----------------------------------------------------------------")
for deployment_name, replicas, ready_replicas, unavailable_replicas in deployment_metrics_info:
print(f"{deployment_name}\t\t{replicas}\t\t{ready_replicas}\t\t{unavailable_replicas}")
def main():
try:
while True:
deployment_metrics_info = get_deployment_metrics()
display_dashboard(deployment_metrics_info)
time.sleep(10) # Wait for 10 seconds before refreshing
except KeyboardInterrupt:
print("\nMonitoring stopped.")
if __name__ == "__main__":
main()
from kubernetes import client, config
from kubernetes.client import configuration
import time
def get_pod_metrics():
configuration.assert_hostname = False
config.load_kube_config() # Load Kubernetes configuration from default location
configuration.assert_hostname = False
api_instance = client.CustomObjectsApi()
# Retrieve metrics of all pods in the "default" namespace
pods_metrics = api_instance.list_namespaced_custom_object(
group="metrics.k8s.io",
version="v1beta1",
namespace="default",
plural="pods"
)
pod_metrics_info = []
for pod in pods_metrics["items"]:
pod_name = pod["metadata"]["name"]
cpu_usage = pod["containers"][0]["usage"]["cpu"]
memory_usage = pod["containers"][0]["usage"]["memory"]
pod_metrics_info.append((pod_name, cpu_usage, memory_usage))
return pod_metrics_info
def display_dashboard(pod_metrics_info):
print("Pod Name\t\tCPU Usage\tMemory Usage")
print("---------------------------------------------")
for pod_name, cpu_usage, memory_usage in pod_metrics_info:
print(f"{pod_name}\t\t{cpu_usage}\t\t{memory_usage}")
def main():
try:
while True:
pod_metrics_info = get_pod_metrics()
display_dashboard(pod_metrics_info)
time.sleep(10) # Wait for 10 seconds before refreshing
except KeyboardInterrupt:
print("\nMonitoring stopped.")
if __name__ == "__main__":
main()
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-server
namespace: kube-system
labels:
k8s-app: metrics-server
spec:
selector:
matchLabels:
k8s-app: metrics-server
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
spec:
serviceAccountName: metrics-server
volumes:
# mount in tmp so we can safely use from-scratch images and/or read-only containers
- name: tmp-dir
emptyDir: {}
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server/metrics-server:v0.3.7
imagePullPolicy: IfNotPresent
args:
- --kubelet-insecure-tls
- --cert-dir=/tmp
- --secure-port=4443
ports:
- name: main-port
containerPort: 4443
protocol: TCP
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
volumeMounts:
- name: tmp-dir
mountPath: /tmp
nodeSelector:
kubernetes.io/os: linux
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-view: "true"
name: system:aggregated-metrics-reader
rules:
- apiGroups:
- metrics.k8s.io
resources:
- pods
- nodes
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
- namespaces
- configmaps
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: metrics-server
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: https
selector:
k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
spec:
selector:
matchLabels:
k8s-app: metrics-server
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
k8s-app: metrics-server
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-preferred-address-types=InternalIP
- --kubelet-insecure-tls
image: k8s.gcr.io/metrics-server/metrics-server:v0.4.1
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /livez
port: https
scheme: HTTPS
periodSeconds: 10
name: metrics-server
ports:
- containerPort: 4443
name: https
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /readyz
port: https
scheme: HTTPS
periodSeconds: 10
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
volumeMounts:
- mountPath: /tmp
name: tmp-dir
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
serviceAccountName: metrics-server
volumes:
- emptyDir: {}
name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
labels:
k8s-app: metrics-server
name: v1beta1.metrics.k8s.io
spec:
group: metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: metrics-server
namespace: kube-system
version: v1beta1
versionPriority: 100
#!/bin/bash
# Number of requests to send
requests=100
# URL to test
#url="http://example.com"
url="http://10.108.160.104"
# Maximum transfer rate in bytes per second (e.g., 1000 bytes/s)
rate_limit=1000000000
# Send requests in parallel using xargs with rate control
seq $requests | xargs -n1 -P10 curl -s --limit-rate $rate_limit -o /dev/null -w "%{http_code}\n" $url
--2024-04-28 11:54:46-- http://10.108.160.104/invoke?param1=test
Connecting to 10.108.160.104:80... failed: Connection refused.
{
"folders": [
{
"path": "../../../800-communications/Conference-LaTeX-template_10-17-19"
}
],
"settings": {}
}
\ No newline at end of file
......@@ -10,6 +10,12 @@ mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#sudo kubeadm token create --print-join-command
# to create....
#kubeadm join 10.129.131.202:6443 --token 7fc5vq.vr3ripjxomnqomgd --discovery-token-ca-cert-hash sha256:12b0ca48c0497cb4d3f94d1debba78ae14a9f883858298331dcfa00987391019
#kubeadm join 10.129.131.202:6443 --token 7pm28n.afbepf5vx2x5cmaw \
# --discovery-token-ca-cert-hash sha256:12b0ca48c0497cb4d3f94d1debba78ae14a9f883858298331dcfa00987391019
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment