Using Kubernetes Locally in MacOS

Using Kubernetes Locally in MacOS

Install Docker

brew cask install docker

Install Kubernetes in Docker

  • Go to menu bar, select the whale icon -> preferences
  • Select Kubernetes tab, then "Enable Kubernetes"

Check that docker is working

~ ❯❯❯ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

Check that Kubernetes is working

~ ❯❯❯ kubectl create deployment hello-node

~ ❯❯❯ kubectl get pods
NAME                          READY   STATUS              RESTARTS   AGE
hello-node-78cd77d68f-8qm4b   0/1     ContainerCreating   0          19s

It may take a while for containers to be created the first time.

~ ❯❯❯ kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
hello-node-78cd77d68f-8qm4b   1/1     Running   0          2m10s

Expose the service

❯❯❯ kubectl expose deployment hello-node --type=LoadBalancer --port=8080
service/hello-node exposed

Check that the service is exposed

~ ❯❯❯ kubectl get services
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   localhost     8080:31077/TCP   5m37s
kubernetes   ClusterIP        <none>        443/TCP          28m

~ ❯❯❯ curl localhost:8080
Hello World!%

Delete the service

~ ❯❯❯ kubectl delete deployment hello-node
deployment.extensions "hello-node" deleted

~ ❯❯❯ kubectl delete service hello-node
service "hello-node" deleted

Using YAML in Kubernetes

Create a yaml file for deployment

apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
    app: nginx
  replicas: 3
      app: nginx
        app: nginx
      - name: nginx
        image: nginx:1.7.9
        - containerPort: 80
apiVersion: v1
kind: Service
  name: nginx
  type: LoadBalancer
  - port: 8080
    targetPort: 80
    protocol: TCP
    name: http
    app: nginx

Run the two spec in the yaml

❯❯❯ kubectl create -f nginx.yaml
deployment.apps/nginx-deployment created
service/nginx created

Check that nginx is working

❯❯❯ curl localhost:8080
<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=""></a>.<br/>
Commercial support is available at
<a href=""></a>.</p>

<p><em>Thank you for using nginx.</em></p>

Delete the deployment and service

❯❯❯ kubectl delete -f nginx.yaml
deployment.apps "nginx-deployment" deleted
service "nginx" deleted