Skip to content
Snippets Groups Projects
Commit 687bef90 authored by Xueshan Feng's avatar Xueshan Feng
Browse files

update README.md

parent dec8a3aa
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@
## Install Docker for Mac
Docker CE Edge installer come with experimental features in Docker Engine enabled by default and these features are configurable on Docker Daemon preferences.
Docker CE Edge installer comes with experimental features in Docker Engine enabled by default and these features are configurable on Docker Daemon preferences.
Go [docker-for-mac Edge](https://download.docker.com/mac/edge/Docker.dmg) to install it. This tutorial is tested with Docker for Mac using Edge channel.
......@@ -22,14 +22,14 @@ Docker for Mac Edge kubernetes integration installed `kubectl v.1.9` command in
for some of the Kubernetes feature to work. Let's fix it and make sure `kubectl` version is 1.10.x:
```console
$ rm /usr/local/bin/kubectl
$ rm /usr/local/bin/kubectl
$ brew reinstlal kubectl
$ kubectl version -c
Flag shorthand -c has been deprecated, please use --client instead.
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.1", GitCommit:"d4ab47518836c750f9949b9e0d387f20fb92260b", GitTreeState:"clean", BuildDate:"2018-04-13T22:29:03Z", GoVersion:"go1.9.5", Compiler:"gc", Platform:"darwin/amd64"}
```
## Enable the kubernetes cluster
## Enable the Kubernetes cluster
Click the `Docker` icon in the status bar, go to `Preferences`, and on the `Kubernetes` tab, check *Enable Kubernetes*. This will start a single node Kubernetes cluster. This might take a while - have a cup of tea and wait for the Kubernetes cluster to be ready.
......@@ -49,9 +49,9 @@ You may have other versions of kubectl in your command path (/opt/bin, $HOME/bin
If you have been working with Kubernetes, you may have multiple cluster configurations in your $HOME/.kube directory. These kubeconfig files contain clusters's API server URL, user credentials etc. You can use *kubectx* to list, show, and switch context. Run `kubectx -h` for details.
* List kube contexts
* List kubernetes contexts
```console
```console
$ kubectx
docker-for-desktop
* eks-preview
......@@ -71,6 +71,7 @@ Switched to context "docker-for-desktop".
* Get kubernetes docker-for-descktop context details:
```console
$ kubectx docker-for-desktop
$ kubectl config view --minify
apiVersion: v1
clusters:
......@@ -97,7 +98,7 @@ Kubernetes master is running at https://localhost:6443
KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
```
* List what's running by default installastion
* List what's running by default installation
```console
$ kubectl get pods --all-namespaces
......@@ -197,7 +198,7 @@ po/redis-slave-865486c9df-b45sq 1/1 Running 0 8m
Here we will demonstrate `kubectl port-forward` feature. We will connect to the Redis master server we just deployed for the guestbook app. Even the port 6379 is not open to the Internet, we can connect to the server by port-forwarding.
* Access to redis-master
- Access to redis-master
```console
$ kubectl port-forward svc/redis-master 6379:6379
......@@ -205,7 +206,7 @@ Forwarding from 127.0.0.1:6379 -> 6379
Handling connection for 6379
```
On another terminal on your local machine, try:
On another terminal on your local machine, the `redis-cli` command talks to redis master through Kubernetes proxy:
```console
$ brew upgrade redis || brew install redis
......@@ -242,9 +243,47 @@ quit
You can Control-C to terminate the port-forward proxy in the other terminal.
* Access guestbook
The guestbook deployment uses "LoadBalancer" service type for guestbook frontend running at 10.105.182.163:80, which means internal pods can find the service endpoint to access guestbook without knowing guestbook pods addresses. To access from outside of the kubernetes cluster network, without expose it to Internet, we can use port-forwarding:
- Access guestbook
When we start the guestbook application, the frontend container register its service name and port with Kubernetes
dns service, as shown blow:
```console
$ kubectl get svc -l app=guestbook
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend ClusterIP 10.105.182.163 <none> 80/TCP 54m
$ kubectl port-forward svc/frontend 8000:80
Forwarding from 127.0.0.1:8000 -> 80
Forwarding from [::1]:8000 -> 80
Handling connection for 8000
Handling connection for 8000
```
In this example the `frontend` service uses "ClusterIP" service type running on IP 10.105.182.163:80, which means
it is only accessible by pods in the cluster. The service name `frontend.default.svc.cluster.local'.
When pods moves, the service IP will not change. Other applications can access service Pod by name.
There are 3 pods servicing the frontend, as show below:
```console
$ kc describe svc frontend
Name: frontend
Namespace: default
Labels: app=guestbook
tier=frontend
Annotations: <none>
Selector: app=guestbook,tier=frontend
Type: ClusterIP
IP: 10.96.34.106
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: 10.1.0.6:80,10.1.0.8:80,10.1.0.9:80
Session Affinity: None
Events: <none>
```
To access from outside of the kubernetes cluster network, without expose it to Internet, we can use port-forwarding:
```console
$ kubectl get svc -l app=guestbook
......@@ -268,15 +307,11 @@ You can terminate the proxy by Control-C to in the proxy window.
We are going to demo how to deploy docker-compose file to Kubernetes cluster.
* First clone this repository:
- Deploy a words web application
```console
$ git clone https://code.stanford.edu/sfeng/docker-for-mac-kubernetes
```
* Deploy a words web application
```console
$ cd docker-for-mac-kubernetes/examples
$ DOCKER_ORCHESTRATOR=kubernetes docker stack deploy docker-web --compose-file docker-compose.yml
Ignoring unsupported options: build
......@@ -288,7 +323,7 @@ Waiting for the stack to be stable and running...
Stack docker-web is stable and running
```
* Verify pods and service are running
- Verify pods and service are running
```console
$ docker stack services docker-web
......@@ -319,17 +354,16 @@ svc/web-published LoadBalancer 10.110.27.41 localhost 80:31119/TCP 1
svc/words ClusterIP None <none> 55555/TCP 1m
```
`svc/web-published` is the frontend that exposed to external host. Just point your browser to
`svc/web-published` is the frontend that exposed to external host (LoadBalancer type). Just point your browser to
http://localhost:80. You get `hello-world!`
* To update the content, edit the web/static/index.html, then
- To update the content, edit the web/static/index.html, then
```console
$ DOCKER_ORCHESTRATOR=kubernetes docker stack up docker-web --compose-file docker-compose.yml
```
* List stacks
- List stacks
```console
$ docker stack ls
......@@ -339,14 +373,14 @@ docker-web 3
## Teardown
* Delete the docker-web applicaiton if you deployed it
- Delete the docker-web applicaiton if you deployed it
```console
$ DOCKER_ORCHESTRATOR=kubernetes docker stack rm docker-web
Removing stack: docker-web
```
* Delete dashboard application
- Delete guestbook application
```console
$ kubeclt delete -f https://raw.githubusercontent.com/kubernetes/examples/master/guestbook/all-in-one/guestbook-all-in-one.yaml
......@@ -359,7 +393,7 @@ service "frontend" deleted
deployment "frontend" deleted
```
* Delete the dashboard
* Delete dashboard
```console
$ kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
......@@ -376,7 +410,7 @@ NOTE: Although you have deleted all the kuberntes workload you installed, your c
## What's next
You now have a Kubernetes cluster on your laptop. You can play, learn, develope your kubernetes applications before you put the load on a production kubernetes system.
You now have a Kubernetes cluster on your laptop. You can play, learn, develope your kubernetes applications before you put the load on a production kubernetes system.
You can use the cluster you just enable to complete [Kubernetes tutorial](https://kubernetes.io/docs/tutorials/).
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment