<p>I am really new on kubernetes. I created a kubernetes cluster with this guide <a href="https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/" rel="nofollow noreferrer">using kubeadm</a>. The cluster consists of one master node and two nodes. Since I want to access the kubernetes web UI via master apiserver (by browser on my laptop), I modified <code>/etc/kubernetes/manifests/kube-apiserver.yaml</code> following these <a href="https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/" rel="nofollow noreferrer">K8 WebUI</a>, <a href="https://github.com/kubernetes/dashboard/wiki/Access-control#basic" rel="nofollow noreferrer">Access control</a>. What I did is that I added the following args in <code>/etc/kubernetes/manifests/kube-apiserver.yaml</code>:</p>

<pre><code>- --authentication-mode=basic
- --basic-auth-file=/etc/kubernetes/auth.csv
- hostPath:
  path: /etc/kubernetes/auth.csv
  name: kubernetes-dashboard
- mountPath: /etc/kubernetes/auth.csv
  name: kubernetes-dashboard
  readOnly: true
</code></pre>

<p>I have password and user name in <code>auth.csv</code> file. However, after I modified the <code>.yaml</code> file, my kube-apiserver process crashed. I checked by running <code>ps -aux|grep kube</code> to know which processes were running. The result was <code>kube-scheduler,kube-controller-manager,/usr/bin/kubelet</code> were all running but <code>kube-apiserver</code> process was not found. <strong>I was wondering what is a graceful way to restart kubernetes and let my cluster come back to the state immediately before changing the <code>.yaml</code>.</strong></p>

<p><strong>In addition, I will appreciate if someone could show me the exact steps to adding username/passwd authentication so that I can access Kubernetes Dashboad UI via browser on my laptop, Or any other way that can help me view the K8 Web UI on my mac laptop</strong>.  I found a similar question <a href="https://stackoverflow.com/questions/41566408/restart-kubernetes-api-server-with-different-options">similar question</a>, but i still can not make it.</p>

<p>The environment:</p>

<ul>
<li>Three ubuntu 16 server: one master two nodes</li>
<li>Kubernetes version 1.9</li>
<li>I can SSH to the three machines and have root privilege.</li>
</ul>

<p><strong>update:</strong> the <code>kube-apiserver.yaml</code> file attached.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  annotations:
    scheduler.alpha.kubernetes.io/critical-pod: ""
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    - --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
    - --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
    - --insecure-port=0
    - --advertise-address=172.16.28.125
    - --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
    - --secure-port=6443
    - --enable-bootstrap-token-auth=true
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    - --requestheader-group-headers=X-Remote-Group
    - --requestheader-allowed-names=front-proxy-client
    - --service-account-key-file=/etc/kubernetes/pki/sa.pub
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
    - --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
    - --allow-privileged=true
    - --requestheader-username-headers=X-Remote-User
    - --requestheader-extra-headers-prefix=X-Remote-Extra-
    - --service-cluster-ip-range=10.96.0.0/12
    - --admission-control=Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,ResourceQuota
    - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
    - --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
    - --authorization-mode=Node,RBAC
    - --etcd-servers=http://127.0.0.1:2379
    - --authentication-mode=basic
    - --basic-auth-file=/etc/kubernetes/auth.csv
    image: gcr.io/google_containers/kube-apiserver-amd64:v1.9.4
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 172.16.28.125
        path: /healthz
        port: 6443
        scheme: HTTPS
      initialDelaySeconds: 15
      timeoutSeconds: 15
    name: kube-apiserver
    resources:
      requests:
        cpu: 250m
    volumeMounts:
    - mountPath: /etc/kubernetes/pki
      name: k8s-certs
      readOnly: true
    - mountPath: /etc/ssl/certs
      name: ca-certs
      readOnly: true
    - mountPath: /etc/pki
      name: ca-certs-etc-pki
      readOnly: true
    - mountPath: /etc/kubernetes/auth.csv
      name: kubernetes-dashboard
      readOnly: true
  hostNetwork: true
  volumes:
  - hostPath:
      path: /etc/kubernetes/pki
      type: DirectoryOrCreate
    name: k8s-certs
  - hostPath:
      path: /etc/ssl/certs
      type: DirectoryOrCreate
    name: ca-certs
  - hostPath:
      path: /etc/pki
      type: DirectoryOrCreate
    name: ca-certs-etc-pki
  - hostPath:
      path: /etc/kubernetes/auth.csv
    name: kubernetes-dashboard
status: {}
</code></pre>

<p>Based on official <a href="https://kubernetes.io/docs/reference/generated/kube-apiserver/" rel="nofollow noreferrer">documentation</a>, <code>--authentication-mode=basic</code> is not a valid option for Kubernetes 1.9 api server.</p>

<p>Try to remove it, hope it will help.</p>

<p>What about exposing your dashboard for external access, the better way is using kube-proxy for that, but if you want to access Dashboard directly, the only more or less secure way is to using <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress</a> for that.</p>

<p>I recommend you to use Helm package manager to manage all installations in your cluster, that is much easier and useful than manually writing all configs.</p>

<p>So, to get a dashboard behind an Ingress on bare-metal, you need:</p>

<ol>
<li>Make sure you cluster work again:)</li>
<li>Install Helm to your PC using <a href="https://docs.helm.sh/using_helm/#installing-helm" rel="nofollow noreferrer">official documentation</a>.</li>
<li>Initialize Helm by call <code>helm init</code>. It will its server path (tiller) to your kubernetes cluster. All details about initialization you can check in the documentation, but usually, it just working.</li>
<li>Now you need to install Ingress. In two words, Ingress in Kubernetes is a special service like a proxy, which will able to you to get static ingress point for applications inside a cluster. We will use Ingress chart based on <a href="https://github.com/kubernetes/charts/tree/master/stable/nginx-ingress" rel="nofollow noreferrer">Nginx</a>. You can check available options in its repo. For installing it with basic configuration, call:</li>
</ol>

<p><code>helm install stable/nginx-ingress --set=controller.service.type=NodePort</code></p>

<ol start="5">
<li>So, now we have an Ingress and its time to install Dashboard using its <a href="https://github.com/kubernetes/charts/tree/master/stable/kubernetes-dashboard" rel="nofollow noreferrer">chart</a>. I highly recommend you to use HTTPS connection instead of HTTP, but now we will use HTTP for making it faster to deploy. You can read about how to enable HTTPS connections on Ingress <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#tls" rel="nofollow noreferrer">here</a> (you will need to add a secret containing your TLS key and cert and set TLS configuration in a chart). So, let's install dashboard:</li>
</ol>

<p><code>helm install stable/kubernetes-dashboard \
  --set=ingress.enabled=True,ingress.hosts=my-dashboard.local</code></p>

<ol start="6">
<li>Now check on which node your Ingress pod working by <code>kubectl describe pod $pod-with-ingress</code> and add IP address of that pod to your <code>hosts</code> files with FQDN <code>my-dashboard.local</code>.</li>
</ol>

<p>Finally, the dashboard has to be available in your browser by <code>http://my-dashboard.local</code> address.</p>

<p>P.S. I highly recommend you also to setup RBAC on your cluster for manage privileges of each user and application in it, including a dashboard.</p>
