diff --git a/k3d/nginx1/deployment-nginx.yaml b/k3d/nginx1/deployment-nginx.yaml new file mode 100644 index 0000000..b93c375 --- /dev/null +++ b/k3d/nginx1/deployment-nginx.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: web + name: web +spec: + replicas: 1 + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + spec: + containers: + - image: nginx:1.19.3 + name: nginx + ports: + - name: http + containerPort: 80 diff --git a/k8s/deployment b/k8s/deployment new file mode 100644 index 0000000..5c4e9d3 --- /dev/null +++ b/k8s/deployment @@ -0,0 +1,21 @@ +mkdir -p ~/web && cd web +kubectl config set-context --current --namespace web +# Starten Sie eine einzelne Instanz von Nginx +kubectl create deployment nginx --image=nginx +# Zeigen Sie die Dokumentation für Pod und SVC Manifeste an +kubectl explain pods.spec +kubectl explain svc.spec +kubectl explain deployment.spec +kubectl create deployment web \ + --image=bee42/whoami:2.2.0 \ + --dry-run=client \ + --output=yaml >deployment.yaml +cat deployment.yaml +kubectl apply -f deployment.yaml +kubectl get deploy +kubectl get pods +kubectl get rs +kubectl delete deploy web +cat deployment.yaml | kubectl apply -f - + +kubectl scale deployment nginx --replicas 1 diff --git a/k8s/install_nginx b/k8s/install_nginx new file mode 100644 index 0000000..8551a2c --- /dev/null +++ b/k8s/install_nginx @@ -0,0 +1,44 @@ +cd ~ +mkdir nginx && cd nginx + +# namespace +kubectl create namespace nginx +kubectl config set-context --current --namespace nginx + +# create pod and service nginx +kubectl run nginx --image nginx --labels run=nginx --dry-run=client -o yaml >nginx.yaml +kubectl apply -f nginx.yaml + +kubectl expose pod nginx -o yaml --port 80 --target-port 80 --dry-run=client >nginx-svc.yaml +kubectl apply -f nginx-svc.yaml + +# access service +kubectl run curl --tty -i --image curlimages/curl -- /bin/sh +curl -i http://nginx +exit + +# start new pod for nginx service ... same labels +kubectl run nginx1 --image nginx --labels run=nginx --dry-run=client -o yaml >nginx1.yaml +kubectl apply -f nginx1.yaml + +# describe manifest +kubectl describe pods nginx +kubectl describe svc nginx + +# deploy pod with nginx 1.19.7 +kubectl set image po nginx nginx=nginx:1.19.7 +kubectl set image po nginx1 nginx1=nginx:1.19.7 + +#or +kubectl set image po *=nginx:1.19.8 -l run=nginx + +kubectl describe pods nginx +kubectl describe pods nginx1 +kubectl describe svc nginx +kubectl get pods +kubectl get ep +kubectl get svc +kubectl attach curl --tty -i +curl http://nginx +exit +kubectl attach -ti curl \ No newline at end of file diff --git a/k8s/nginx/nginx-svc.yaml b/k8s/nginx/nginx-svc.yaml new file mode 100644 index 0000000..84ef950 --- /dev/null +++ b/k8s/nginx/nginx-svc.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + namespace: nginx + labels: + name: nginx + name: nginx +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 80 + selector: + run: nginx +status: + loadBalancer: {} diff --git a/k8s/nginx/nginx1.yaml b/k8s/nginx/nginx1.yaml new file mode 100644 index 0000000..aa2ed5a --- /dev/null +++ b/k8s/nginx/nginx1.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + creationTimestamp: null + labels: + name: nginx + name: nginx1 +spec: + containers: + - image: nginx + name: nginx1 + resources: {} + dnsPolicy: ClusterFirst + restartPolicy: Always +status: {} diff --git a/k8s/nginx/nginx_namespace.yaml b/k8s/nginx/nginx_namespace.yaml new file mode 100644 index 0000000..65d4f13 --- /dev/null +++ b/k8s/nginx/nginx_namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nginx \ No newline at end of file diff --git a/k8s/nginx/nginx_pod.yaml b/k8s/nginx/nginx_pod.yaml new file mode 100644 index 0000000..eec9225 --- /dev/null +++ b/k8s/nginx/nginx_pod.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx + namespace: nginx + labels: + name: nginx +spec: + containers: + - name: nginx + image: nginx:1.19.3 + resources: + limits: + memory: "128Mi" + cpu: "500m" + ports: + - containerPort: 80 \ No newline at end of file diff --git a/k8s/nginx/nginx_service.yaml b/k8s/nginx/nginx_service.yaml new file mode 100644 index 0000000..c51afd1 --- /dev/null +++ b/k8s/nginx/nginx_service.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx + namespace: nginx + labels: + name: nginx +spec: + ports: + - protocol: TCP + port: 80 + targetPort: 80 \ No newline at end of file diff --git a/k8s/pods b/k8s/pods index 098961e..5f79f4b 100644 --- a/k8s/pods +++ b/k8s/pods @@ -13,4 +13,58 @@ kubectl run whoami --image bee42/whoami:2.2.0 --expose --port 80 kubectl get pod whoami -o yaml # kann zur erstellung der YAML genutzt werden. -kubectl run whoami2 --image bee42/whoami:2.2.0 --labels=run=whoami --dry-run=client -o yaml >whoami-pod.yaml \ No newline at end of file +kubectl run whoami2 --image bee42/whoami:2.2.0 --labels=run=whoami --dry-run=client -o yaml >whoami-pod.yaml + +# Show Labels +kubectl get pods --show-labels + +# Test iin Pod +kubectl run curl --tty -i --image curlimages/curl -- /bin/sh +curl -i http://nginx + +# port weiterleiten +kubectl port-forward services/nginx 8091:80 & + +# scale Pods + +kubectl scale deployments/web --replicas=3 + +kubectl set image deployment/web nginx=nginx:1.19.4 +kubectl rollout status -w deployment/web +kubectl rollout undo deployment/web +kubectl rollout status -w deployment/web +kubectl rollout history deployment/web +kubectl rollout undo deployment/web --to-revision=1 + +# Better annotate replicaset !! +kubectl annotate deployment web kubernetes.io/change-cause="Release 1.19.3" --overwrite=true + +#or + +kubectl get rs +NAME DESIRED CURRENT READY AGE +web-85dfdff5d 0 0 0 28m +web-548df7676c 0 0 0 46m +web-6f4f87dd45 3 3 3 26m +kubectl annotate rs web-6f4f87dd45 kubernetes.io/change-cause="Release 1.19.5" --overwrite=true +kubectl rollout history deploy web +deployment.apps/web +REVISION CHANGE-CAUSE +4 +5 +6 Release 1.19.5 +# new deployment + +kubectl get rs -o json |jq -r .items[].metadata.annotations.\"deployment.kubernetes.io/revision\" +3 +6 +5 + + + +#cat pod.json | kubectl replace -f - +#kubectl replace --force -f ./pod.json +kubectl get pods +kubectl get pod -o yaml | sed 's/\(image: nginx\):.*$/\1:1.19.3/' | kubectl replace -f - + +#kubectl get pod web-548df7676c-v48kv -o yaml | sed 's/\(image: nginx\):.*$/\1:1.19.4/' | kubectl replace -f - web-548df7676c-rzp7v \ No newline at end of file diff --git a/selinux_arch b/selinux_arch new file mode 100644 index 0000000..3c271ad --- /dev/null +++ b/selinux_arch @@ -0,0 +1 @@ +https://github.com/archlinuxhardened/selinux \ No newline at end of file