Browse Source

Add 'kubernetes-example/kubectl-intro.md'

master
srieger 4 years ago
parent
commit
605eb739c2
  1. 115
      kubernetes-example/kubectl-intro.md

115
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
```
Loading…
Cancel
Save