better readability

This commit is contained in:
iwilltry42 2019-05-15 08:40:48 +02:00
parent 396e4dd196
commit 07febe44c0

View File

@ -48,69 +48,76 @@ Example Workflow: Create a new cluster and use it with `kubectl`
### Expose services ### Expose services
#### via Ingress #### 1. via Ingress
1. Create a cluster, mapping the ingress port 80 to localhost:8081 1. Create a cluster, mapping the ingress port 80 to localhost:8081
`k3d create --api-port 6550 --publish 8081:80 --workers 2`
`k3d create --api-port 6550 --publish 8081:80 --workers 2`
2. Get the kubeconfig file 2. Get the kubeconfig file
`export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')"`
`export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')"`
3. Create a nginx deployment 3. Create a nginx deployment
`kubectl create deployment nginx --image=nginx`
`kubectl create deployment nginx --image=nginx`
4. Create a ClusterIP service for it 4. Create a ClusterIP service for it
`kubectl create service clusterip nginx --tcp=80:80`
`kubectl create service clusterip nginx --tcp=80:80`
5. Create an ingress object for it with `kubectl apply -f` 5. Create an ingress object for it with `kubectl apply -f`
```YAML ```YAML
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: Ingress kind: Ingress
metadata: metadata:
name: nginx name: nginx
annotations: annotations:
ingress.kubernetes.io/ssl-redirect: "false" ingress.kubernetes.io/ssl-redirect: "false"
spec: spec:
rules: rules:
- http: - http:
paths: paths:
- path: / - path: /
backend: backend:
serviceName: nginx serviceName: nginx
servicePort: 80 servicePort: 80
``` ```
6. Curl it via localhost 6. Curl it via localhost
`curl localhost:8081/`
### via NodePort `curl localhost:8081/`
#### 2. via NodePort
1. Create a cluster, mapping the port 30080 from worker-0 to localhost:8082 1. Create a cluster, mapping the port 30080 from worker-0 to localhost:8082
`k3d create --publish 8082:30080@k3d-k3s-default-worker-0 --workers 2 -a 6550`
`k3d create --publish 8082:30080@k3d-k3s-default-worker-0 --workers 2 -a 6550`
... (Steps 2 and 3 like above) ... ... (Steps 2 and 3 like above) ...
4. Create a NodePort service for it with `kubectl apply -f` 4. Create a NodePort service for it with `kubectl apply -f`
```YAML ```YAML
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
labels: labels:
app: nginx app: nginx
name: nginx name: nginx
spec: spec:
ports: ports:
- name: 80-80 - name: 80-80
nodePort: 30080 nodePort: 30080
port: 80 port: 80
protocol: TCP protocol: TCP
targetPort: 80 targetPort: 80
selector: selector:
app: nginx app: nginx
type: NodePort type: NodePort
``` ```
5. Curl it via localhost 5. Curl it via localhost
`curl localhost:8082/`
`curl localhost:8082/`