You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Enable Kubernetes

From Docker Preferences, enable Kubernetes.

Check to see if it is running by issuing the following command:

> kubectl get nodes

NAME                 STATUS   ROLES    AGE   VERSION
docker-for-desktop   Ready    master   5h    v1.10.3


Install the Dashboard

> kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml


Verify that it is installed:

> kubectl get pods --all-namespaces -o wide


NAMESPACE     NAME                                         READY   STATUS    RESTARTS   AGE   IP             NODE
docker        compose-74649b4db6-zpb5t                     1/1     Running   0          5h    10.1.0.3       docker-for-desktop
docker        compose-api-8477889868-jfzph                 1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   etcd-docker-for-desktop                      1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   kube-apiserver-docker-for-desktop            1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   kube-controller-manager-docker-for-desktop   1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   kube-dns-86f4d74b45-txr8w                    3/3     Running   0          5h    10.1.0.2       docker-for-desktop
kube-system   kube-proxy-q5vrd                             1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   kube-scheduler-docker-for-desktop            1/1     Running   0          5h    192.168.65.3   docker-for-desktop
kube-system   kubernetes-XXX        1/1     Running   0          50s   10.1.0.4       docker-for-desktop



Create a dashboard admin user: 

vi dashboard-adminuser.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system


> kubectl apply -f dashboard-adminuser.yaml

serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created


Get the Token for the created user

> kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

Name:         admin-user-token-shqsn
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: 8ab8e997-1069-11e9-9ec0-025000000001

Type:  kubernetes.io/service-account-token

Data
====
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXNocXNuIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4YWI4ZTk5Ny0xMDY5LTExZTktOWVjMC0wMjUwMDAwMDAwMDEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.MejrO_QQmPOg-ga5wXatkBBsTD5NbT0GHyIdxK5Ki3L4Yt1ZjTB8cCmhC2cN7kpus6RXN8fZpeB72UohSd1JBOJbJ9QFobSfEXXgKWD9r366hkuqP3lObTUexNDTsVlx12WUD6Vp_QAkq8ItIQ3o6xdeA2udhrAB8E55vPhK2PzyuaLHkkT-87CmG1amdn9mpZGv4FNHUvS7TYHvHs2ShisWZgLsC9hF8t_TngGWcUA5OXqH_5CzdLAYj3f2qXwXmbYiwrHT9T8PL3gchDDDuvhDxjesWqdWRjKYDU1mJ5oNskEiBQcRF0mOwl5BlZm8VwNAV1CUdKKXeSeI7_cZ6g
ca.crt:     1025 bytes
namespace:  11 bytes


Create port forwarding for the dashboard 

You can either setup port forwarding or create a service for the dasboard.

To create a service:

> kubectl expose deployment kubernetes-dashboard --namespace=kube-system --type=LoadBalancer --name=dashboard


To port-forward

> kubectl port-forward $(kubectl -n kube-system get pods |grep kubernetes-dashboard |awk '{print $1}') 8443:8443 --namespace=kube-system


Open your browser

Navigate to:

https://localhost:8443


Sign in using the token previously retrieved.



Install Sample Pod

> vi nginx-example.yaml

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80


> kubectl apply -f nginx-example.yaml


> kubectl expose deployment nginx-deployment --type=LoadBalancer --name=nginx


Open your browser to http://localhost/


References



  • No labels