From 605eb739c25262cbc0b3569690df3db0b90e2a3e Mon Sep 17 00:00:00 2001 From: srieger Date: Wed, 9 Jun 2021 22:20:11 +0200 Subject: [PATCH 1/4] Add 'kubernetes-example/kubectl-intro.md' --- kubernetes-example/kubectl-intro.md | 115 ++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 kubernetes-example/kubectl-intro.md diff --git a/kubernetes-example/kubectl-intro.md b/kubernetes-example/kubectl-intro.md new file mode 100644 index 0000000..b6497f7 --- /dev/null +++ b/kubernetes-example/kubectl-intro.md @@ -0,0 +1,115 @@ +# Introduction to kubectl + +## Deployment of the needed description in kubernetes + +These are two approaches to create the description in Kuberentes: + +```bash +# create a namespace +kubectl create namespace web-test + +# Then choose one of the following ways: +# (1) Create the description +kubectl create -f nginx.yml -f service.yml + +# (2) Create or update descriptions if existing +kubectl apply -f nginx.yml -f service.yml +``` + +## To show it is working + +Here are some useful commands: + +```bash +# show nodes +kubectl get nodes + +# show pods for our namespace +kubectl get -n web-test pods + +# show deployments for our namespace +kubectl get -n web-test deployment + +# show services for our namespace +kubectl get -n web-test service + +# show logs of deployed nginx instances +kubectl logs -n web-test deployment/nginx-deployment +``` + +## Scaling up and down + +```bash +# scale up instances to 5 +kubectl scale deployment/nginx-deployment --replicas=5 + +# scale down instances again to 3 +kubectl scale deployment/nginx-deployment --replicas=3 + +``` + + +## To see it is working in the browser ;) + +The nginx instances are reachable at the floating ips of the **node**-instances at port **30007** in our case. + + +## Many other things can be done ;) + +- Autoscaling +- Detailled Service functions (LoadBalancer, ...) +- Dashboard +- FaaS Setup ;) +- ... + + +## Appendix + +### Nginx description + +*nginx.yml:* +```yml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: web-test +spec: + selector: + matchLabels: + app: nginx-deployment + replicas: 3 # tells deployment to run 3 pods matching the template + template: + metadata: + labels: + app: nginx-deployment + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 + +``` + +### Nginx service description + +*service.yml:* +```yml +apiVersion: v1 +kind: Service +metadata: + name: nginx-service + namespace: web-test +spec: + type: NodePort + selector: + app: nginx-deployment + ports: + # By default and for convenience, the `targetPort` is set to the same value as the `port` field. + - port: 80 + targetPort: 80 + # Optional field + # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) + nodePort: 30007 +``` \ No newline at end of file From 56d42ff1dc2f8804c8a4b8f5dff391376f0f5097 Mon Sep 17 00:00:00 2001 From: srieger Date: Wed, 9 Jun 2021 22:25:18 +0200 Subject: [PATCH 2/4] Update 'kubernetes-example/kubectl-intro.md' --- kubernetes-example/kubectl-intro.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kubernetes-example/kubectl-intro.md b/kubernetes-example/kubectl-intro.md index b6497f7..452fbaa 100644 --- a/kubernetes-example/kubectl-intro.md +++ b/kubernetes-example/kubectl-intro.md @@ -8,7 +8,7 @@ These are two approaches to create the description in Kuberentes: # create a namespace kubectl create namespace web-test -# Then choose one of the following ways: +# Then choose one way: # (1) Create the description kubectl create -f nginx.yml -f service.yml @@ -31,7 +31,7 @@ kubectl get -n web-test pods kubectl get -n web-test deployment # show services for our namespace -kubectl get -n web-test service +kubectl show -n web-test service # show logs of deployed nginx instances kubectl logs -n web-test deployment/nginx-deployment @@ -67,7 +67,6 @@ The nginx instances are reachable at the floating ips of the **node**-instances ### Nginx description -*nginx.yml:* ```yml apiVersion: apps/v1 kind: Deployment @@ -94,7 +93,6 @@ spec: ### Nginx service description -*service.yml:* ```yml apiVersion: v1 kind: Service @@ -111,5 +109,5 @@ spec: targetPort: 80 # Optional field # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) - nodePort: 30007 + nodePort: 3000 ``` \ No newline at end of file From 350d47b120e0c881ae5c1bcba13d86ac87ea63ba Mon Sep 17 00:00:00 2001 From: srieger Date: Wed, 9 Jun 2021 22:25:42 +0200 Subject: [PATCH 3/4] Update 'kubernetes-example/kubectl-intro.md' --- kubernetes-example/kubectl-intro.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kubernetes-example/kubectl-intro.md b/kubernetes-example/kubectl-intro.md index 452fbaa..b6497f7 100644 --- a/kubernetes-example/kubectl-intro.md +++ b/kubernetes-example/kubectl-intro.md @@ -8,7 +8,7 @@ These are two approaches to create the description in Kuberentes: # create a namespace kubectl create namespace web-test -# Then choose one way: +# Then choose one of the following ways: # (1) Create the description kubectl create -f nginx.yml -f service.yml @@ -31,7 +31,7 @@ kubectl get -n web-test pods kubectl get -n web-test deployment # show services for our namespace -kubectl show -n web-test service +kubectl get -n web-test service # show logs of deployed nginx instances kubectl logs -n web-test deployment/nginx-deployment @@ -67,6 +67,7 @@ The nginx instances are reachable at the floating ips of the **node**-instances ### Nginx description +*nginx.yml:* ```yml apiVersion: apps/v1 kind: Deployment @@ -93,6 +94,7 @@ spec: ### Nginx service description +*service.yml:* ```yml apiVersion: v1 kind: Service @@ -109,5 +111,5 @@ spec: targetPort: 80 # Optional field # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) - nodePort: 3000 + nodePort: 30007 ``` \ No newline at end of file From 3a1c789fcf730384efc05511ba92d9bf649a8eb5 Mon Sep 17 00:00:00 2001 From: Timo Geier Date: Thu, 10 Jun 2021 11:13:55 +0200 Subject: [PATCH 4/4] Improved Kubernetes cluster documentation --- kubernetes-example/kubectl-intro.md | 59 +++++++++++++++++++++++++++-- kubernetes-example/nginx.yml | 20 ++++++++++ kubernetes-example/service.yml | 16 ++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 kubernetes-example/nginx.yml create mode 100644 kubernetes-example/service.yml diff --git a/kubernetes-example/kubectl-intro.md b/kubernetes-example/kubectl-intro.md index b6497f7..268500e 100644 --- a/kubernetes-example/kubectl-intro.md +++ b/kubernetes-example/kubectl-intro.md @@ -1,8 +1,61 @@ # Introduction to kubectl +## Prerequisites + +For using this you must install the following tools: + +- Python +- Pip +- Kubectl +- Openstack-Client + +### Python + +Install python and pip for your OS, if it is not installed. This is already done at the NetLab PCs. + +### Installing kubectl and arkade + +Run this in a **bash** terminal to download arkade and install kubectl: + +For windows you can use e.g. the **Git Bash** terminal. + +```bash +curl -sLS https://dl.get-arkade.dev | sh +arkade get kubectl +# To load the path to the binary +export PATH=$PATH:$HOME/.arkade/bin/ +``` + +With arkade you can also install other tools: ```arkade get``` to see all possibilities. + +### Openstack Client + +To install the Openstack client and the magnum package: + +If you are using Windows, you must start the bash terminal with **Administrator** privileges! + +```bash +pip3 install openstackclient python-magnumclient +# Download the Openstack RC File from your Openstack account +# Load the file +source {USERNAME}-openrc.sh +``` + +### Download the kubeconfig + +Download the kubeconfig file for your cluster from OpenStack. + +```bash +# Before using this, check if Openstack RC File is loaded! +openstack coe cluster config {CLUSTER_NAME} +# Then run the given command in terminal +export ... +# Now you are able to run kubectl commands at your Kubernetes cluster +``` + ## Deployment of the needed description in kubernetes -These are two approaches to create the description in Kuberentes: +These are two approaches to create the description in Kubernetes: ```bash # create a namespace @@ -41,10 +94,10 @@ kubectl logs -n web-test deployment/nginx-deployment ```bash # scale up instances to 5 -kubectl scale deployment/nginx-deployment --replicas=5 +kubectl scale -n web-test deployment/nginx-deployment --replicas=5 # scale down instances again to 3 -kubectl scale deployment/nginx-deployment --replicas=3 +kubectl scale -n web-test deployment/nginx-deployment --replicas=3 ``` diff --git a/kubernetes-example/nginx.yml b/kubernetes-example/nginx.yml new file mode 100644 index 0000000..e14fd3b --- /dev/null +++ b/kubernetes-example/nginx.yml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: web-test +spec: + selector: + matchLabels: + app: nginx-deployment + replicas: 3 # tells deployment to run 3 pods matching the template + template: + metadata: + labels: + app: nginx-deployment + spec: + containers: + - name: nginx + image: nginx:latest + ports: + - containerPort: 80 \ No newline at end of file diff --git a/kubernetes-example/service.yml b/kubernetes-example/service.yml new file mode 100644 index 0000000..1638a45 --- /dev/null +++ b/kubernetes-example/service.yml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-service + namespace: web-test +spec: + type: NodePort + selector: + app: nginx-deployment + ports: + # By default and for convenience, the `targetPort` is set to the same value as the `port` field. + - port: 80 + targetPort: 80 + # Optional field + # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) + nodePort: 30007 \ No newline at end of file