{"id":20042408,"url":"https://github.com/richardsonlima/kubernetes-docker-in-docker-cluster","last_synced_at":"2025-05-05T08:32:32.965Z","repository":{"id":43652661,"uuid":"143816516","full_name":"richardsonlima/kubernetes-docker-in-docker-cluster","owner":"richardsonlima","description":"KubeWave - Kubernetes Cluster - Docker Inception","archived":false,"fork":false,"pushed_at":"2022-02-26T00:46:41.000Z","size":524,"stargazers_count":17,"open_issues_count":5,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T19:52:41.062Z","etag":null,"topics":["docker","k8s","k8s-cluster","k8s-deployer","kubernetes","kubernetes-cluster","kubernetes-deployment"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/richardsonlima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-07T03:48:13.000Z","updated_at":"2022-08-28T01:53:07.000Z","dependencies_parsed_at":"2022-07-25T23:49:28.740Z","dependency_job_id":null,"html_url":"https://github.com/richardsonlima/kubernetes-docker-in-docker-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsonlima%2Fkubernetes-docker-in-docker-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsonlima%2Fkubernetes-docker-in-docker-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsonlima%2Fkubernetes-docker-in-docker-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardsonlima%2Fkubernetes-docker-in-docker-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richardsonlima","download_url":"https://codeload.github.com/richardsonlima/kubernetes-docker-in-docker-cluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252466888,"owners_count":21752456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","k8s","k8s-cluster","k8s-deployer","kubernetes","kubernetes-cluster","kubernetes-deployment"],"created_at":"2024-11-13T10:51:35.128Z","updated_at":"2025-05-05T08:32:31.042Z","avatar_url":"https://github.com/richardsonlima.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KubeWave [![CircleCI](https://circleci.com/gh/richardsonlima/kubernetes-docker-in-docker-cluster/tree/master.svg?style=svg)](https://circleci.com/gh/richardsonlima/kubernetes-docker-in-docker-cluster/tree/master) [![Travis CI](https://travis-ci.org/richardsonlima/kubernetes-docker-in-docker-cluster.svg?branch=master)](https://travis-ci.org/richardsonlima/kubernetes-docker-in-docker-cluster)\n\n\u003cimg src=\"/pics/logo.png\" width=\"155px\" alt=\"kubewolf logo\"\u003e\n\nA Kubernetes multi-node cluster for developer of Kubernetes or extend Kubernetes. Based on kubeadm and Docker in\nDocker.\n\n## Requirements\nDocker 1.12+ is recommended. If you're not using one of the\npreconfigured scripts (see below) and not building from source, it's\nbetter to have `kubectl` executable in your path matching the\nversion of k8s binaries you're using (i.e. for example better don't\nuse `kubectl` 1.9.x with `hyperkube` 1.8.x).\n\n`kubernetes-docker-in-docker-cluster` supports k8s versions 1.8.x, 1.9.x .\n\n**Run `kubernetes-docker-in-docker-cluster` on Docker with `btrfs`\nstorage driver is not supported.**\n\nBy default `kubernetes-docker-in-docker-cluster` uses dockerized builds, so no Go\ninstallation is necessary even if you're building Kubernetes from\nsource. If you want you can overridde this behavior by setting\n`KUBEADM_DIND_LOCAL` to a non-empty value in [config.sh](config.sh).\n\n### Mac OS X considerations\n\nEnsure to have `md5sha1sum` installed. If not existing can be installed via `brew install md5sha1sum`.\n\n## Using preconfigured scripts\n`kubernetes-cluster-over-docker` currently provides preconfigured scripts for\nKubernetes 1.8, 1.9. This may be convenient for use with\nprojects that extend or use Kubernetes. For example, you can start\nKubernetes 1.9 like this:\n\n```console\n\n# Downloading kubectl (1.9.9 - for linux) \n$ curl -O https://storage.googleapis.com/kubernetes-release/release/v1.9.9/bin/linux/amd64/kubectl\n$ mv kubectl /usr/local/bin/\n\n$ wget https://raw.githubusercontent.com/richardsonlima/kubernetes-docker-in-docker-cluster/master/kubernetes-docker-in-docker-cluster-v1.9.sh\n$ chmod +x kubernetes-docker-in-docker-cluster-v1.9.sh\n\n$ # start the cluster\n$ ./kubernetes-docker-in-docker-cluster-v1.9.sh up\n\n$ # also you can start the cluster with 3 nodes\n$ NUM_NODES=3 ./kubernetes-docker-in-docker-cluster-v1.9.sh up\n\n$ ./kubernetes-docker-in-docker-cluster-v1.9.sh initial-config \n\n$ kubectl --kubeconfig ~/.kube/config get pods --all-namespaces\n\n# Creating a namespace\n$ kubectl --kubeconfig ~/.kube/config create namespace test-docker-in-docker\n\n$ kubectl --kubeconfig ~/.kube/config get nodes\nNAME          STATUS    ROLES     AGE       VERSION\nkube-master   Ready     master    57m       v1.9.9\nkube-node-1   Ready     \u003cnone\u003e    56m       v1.9.9\nkube-node-2   Ready     \u003cnone\u003e    56m       v1.9.9\nkube-node-3   Ready     \u003cnone\u003e    56m       v1.9.9\n\n$ # k8s dashboard available at http://localhost:8080/api/v1/namespaces/kube-system/services/kubernetes-dashboard:/proxy\n\n$ # restart the cluster, this should happen much quicker than initial startup\n$ ./kubernetes-docker-in-docker-cluster-v1.9.sh up\n\n$ # stop the cluster\n$ ./kubernetes-docker-in-docker-cluster-v1.9.sh down\n\n$ # remove containers and volumes\n$ ./kubernetes-docker-in-docker-cluster-v1.9.sh clean\n```\n\nTerminal session test::\n[![asciicast](https://asciinema.org/a/195341.png)](https://asciinema.org/a/195341?autoplay=1) \n\nReplace 1.8 with 1.9 or 1.10 to use other Kubernetes versions.\n**Important note:** you need to do `./kubernetes-docker-in-docker-cluster-....sh clean` when\nyou switch between Kubernetes versions (but no need to do this between\nrebuilds if you use `BUILD_HYPERKUBE=y` like described below).\n\n### Using local cluster with JenkinsX \n\n \n```console\n# Get jx (https://jenkins-x.io/)\ncurl -L https://github.com/jenkins-x/jx/releases/download/v1.3.168/jx-darwin-amd64.tar.gz | tar xzv \nsudo mv jx /usr/local/bin\n\n# Install JenkinsX on DIND K8S Cluster\njx install --provider=kubernetes --on-premise (or  --local-cloud-environment)\n```\n\n## Deploy a Guestbook Example App\n\nThis example shows how to build a simple multi-tier web application using Kubernetes and Docker. The application consists of a web front end, Redis master for storage, and replicated set of Redis slaves, all for which we will create Kubernetes replication controllers, pods, and services.\n\n##### Table of Contents\n\n * [Step Zero: Prerequisites](#step-zero)\n * [Step One: Create the Redis master pod](#step-one)\n * [Step Two: Create the Redis master service](#step-two)\n * [Step Three: Create the Redis slave pods](#step-three)\n * [Step Four: Create the Redis slave service](#step-four)\n * [Step Five: Create the guestbook pods](#step-five)\n * [Step Six: Create the guestbook service](#step-six)\n * [Step Seven: View the guestbook](#step-seven)\n * [Step Eight: Cleanup](#step-eight)\n\n### Step Zero: Prerequisites \u003ca id=\"step-zero\"\u003e\u003c/a\u003e\n\nThis example assumes that you have a working cluster.  \n\n**Tip:** View all the `kubectl` commands, including their options and descriptions in the [kubectl CLI reference](https://kubernetes.io/docs/user-guide/kubectl-overview/).\n\n### Step One: Create the Redis master pod\u003ca id=\"step-one\"\u003e\u003c/a\u003e\n\nUse the `examples/guestbook-go/redis-master-controller.json` file to create a [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) and Redis master [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/). The pod runs a Redis key-value server in a container. Using a replication controller is the preferred way to launch long-running pods, even for 1 replica, so that the pod benefits from the self-healing mechanism in Kubernetes (keeps the pods alive).\n\n1. Use the [redis-master-controller.json](redis-master-controller.json) file to create the Redis master replication controller in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/redis-master-controller.json\n    replicationcontrollers/redis-master\n    ```\n\n2. To verify that the redis-master controller is up, list the replication controllers you created in the cluster with the `kubectl get rc` command(if you don't specify a `--namespace`, the `default` namespace will be used. The same below):\n\n    ```console\n    $ kubectl get rc\n    CONTROLLER             CONTAINER(S)            IMAGE(S)                    SELECTOR                         REPLICAS\n    redis-master           redis-master            gurpartap/redis             app=redis,role=master            1\n    ...\n    ```\n\n    Result: The replication controller then creates the single Redis master pod.\n\n3. To verify that the redis-master pod is running, list the pods you created in cluster with the `kubectl get pods` command:\n\n    ```console\n    $ kubectl get pods\n    NAME                        READY     STATUS    RESTARTS   AGE\n    redis-master-xx4uv          1/1       Running   0          1m\n    ...\n    ```\n\n    Result: You'll see a single Redis master pod and the machine where the pod is running after the pod gets placed (may take up to thirty seconds).\n\n### Step Two: Create the Redis master service \u003ca id=\"step-two\"\u003e\u003c/a\u003e\n\nA Kubernetes [service](https://kubernetes.io/docs/concepts/services-networking/service/) is a named load balancer that proxies traffic to one or more pods. The services in a Kubernetes cluster are discoverable inside other pods via environment variables or DNS.\n\nServices find the pods to load balance based on pod labels. The pod that you created in Step One has the label `app=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service.\n\n1. Use the [redis-master-service.json](redis-master-service.json) file to create the service in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/redis-master-service.json\n    services/redis-master\n    ```\n\n2. To verify that the redis-master service is up, list the services you created in the cluster with the `kubectl get services` command:\n\n    ```console\n    $ kubectl get services\n    NAME              CLUSTER_IP       EXTERNAL_IP       PORT(S)       SELECTOR               AGE\n    redis-master      10.0.136.3       \u003cnone\u003e            6379/TCP      app=redis,role=master  1h\n    ...\n    ```\n\n    Result: All new pods will see the `redis-master` service running on the host (`$REDIS_MASTER_SERVICE_HOST` environment variable) at port 6379, or running on `redis-master:6379`. After the service is created, the service proxy on each node is configured to set up a proxy on the specified port (in our example, that's port 6379).\n\n\n### Step Three: Create the Redis slave pods \u003ca id=\"step-three\"\u003e\u003c/a\u003e\n\nThe Redis master we created earlier is a single pod (REPLICAS = 1), while the Redis read slaves we are creating here are 'replicated' pods. In Kubernetes, a replication controller is responsible for managing the multiple instances of a replicated pod.\n\n1. Use the file [redis-slave-controller.json](redis-slave-controller.json) to create the replication controller by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/redis-slave-controller.json\n    replicationcontrollers/redis-slave\n    ```\n\n2. To verify that the redis-slave controller is running, run the `kubectl get rc` command:\n\n    ```console\n    $ kubectl get rc\n    CONTROLLER              CONTAINER(S)            IMAGE(S)                         SELECTOR                    REPLICAS\n    redis-master            redis-master            redis                            app=redis,role=master       1\n    redis-slave             redis-slave             kubernetes/redis-slave:v2        app=redis,role=slave        2\n    ...\n    ```\n\n    Result: The replication controller creates and configures the Redis slave pods through the redis-master service (name:port pair, in our example that's `redis-master:6379`).\n\n\n3. To verify that the Redis master and slaves pods are running, run the `kubectl get pods` command:\n\n    ```console\n    $ kubectl get pods\n    NAME                          READY     STATUS    RESTARTS   AGE\n    redis-master-xx4uv            1/1       Running   0          18m\n    redis-slave-b6wj4             1/1       Running   0          1m\n    redis-slave-iai40             1/1       Running   0          1m\n    ...\n    ```\n\n    Result: You see the single Redis master and two Redis slave pods.\n\n### Step Four: Create the Redis slave service \u003ca id=\"step-four\"\u003e\u003c/a\u003e\n\nJust like the master, we want to have a service to proxy connections to the read slaves. In this case, in addition to discovery, the Redis slave service provides transparent load balancing to clients.\n\n1. Use the [redis-slave-service.json](redis-slave-service.json) file to create the Redis slave service by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/redis-slave-service.json\n    services/redis-slave\n    ```\n\n2. To verify that the redis-slave service is up, list the services you created in the cluster with the `kubectl get services` command:\n\n    ```console\n    $ kubectl get services\n    NAME              CLUSTER_IP       EXTERNAL_IP       PORT(S)       SELECTOR               AGE\n    redis-master      10.0.136.3       \u003cnone\u003e            6379/TCP      app=redis,role=master  1h\n    redis-slave       10.0.21.92       \u003cnone\u003e            6379/TCP      app-redis,role=slave   1h\n    ...\n    ```\n\n    Result: The service is created with labels `app=redis` and `role=slave` to identify that the pods are running the Redis slaves.\n\nTip: It is helpful to set labels on your services themselves--as we've done here--to make it easy to locate them later.\n\n### Step Five: Create the guestbook pods \u003ca id=\"step-five\"\u003e\u003c/a\u003e\n\nThis is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni) based) server that is configured to talk to either the slave or master services depending on whether the request is a read or a write. The pods we are creating expose a simple JSON interface and serves a jQuery-Ajax based UI. Like the Redis slave pods, these pods are also managed by a replication controller.\n\n1. Use the [guestbook-controller.json](guestbook-controller.json) file to create the guestbook replication controller by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/guestbook-controller.json\n    replicationcontrollers/guestbook\n    ```\n\n Tip: If you want to modify the guestbook code open the `_src` of this example and read the README.md and the Makefile. If you have pushed your custom image be sure to update the `image` accordingly in the guestbook-controller.json.\n\n2. To verify that the guestbook replication controller is running, run the `kubectl get rc` command:\n\n    ```console\n    $ kubectl get rc\n    CONTROLLER            CONTAINER(S)         IMAGE(S)                               SELECTOR                  REPLICAS\n    guestbook             guestbook            k8s.gcr.io/guestbook:v3  app=guestbook             3\n    redis-master          redis-master         redis                                  app=redis,role=master     1\n    redis-slave           redis-slave          kubernetes/redis-slave:v2              app=redis,role=slave      2\n    ...\n    ```\n\n3. To verify that the guestbook pods are running (it might take up to thirty seconds to create the pods), list the pods you created in cluster with the `kubectl get pods` command:\n\n    ```console\n    $ kubectl get pods\n    NAME                           READY     STATUS    RESTARTS   AGE\n    guestbook-3crgn                1/1       Running   0          2m\n    guestbook-gv7i6                1/1       Running   0          2m\n    guestbook-x405a                1/1       Running   0          2m\n    redis-master-xx4uv             1/1       Running   0          23m\n    redis-slave-b6wj4              1/1       Running   0          6m\n    redis-slave-iai40              1/1       Running   0          6m\n    ... \n    ```\n\n    Result: You see a single Redis master, two Redis slaves, and three guestbook pods.\n\n### Step Six: Create the guestbook service \u003ca id=\"step-six\"\u003e\u003c/a\u003e\n\nJust like the others, we create a service to group the guestbook pods but this time, to make the guestbook front end externally visible, we specify `\"type\": \"LoadBalancer\"`.\n\n1. Use the [guestbook-service.json](guestbook-service.json) file to create the guestbook service by running the `kubectl create -f` *`filename`* command:\n\n    ```console\n    $ kubectl create -f examples/guestbook-go/guestbook-service.json\n    ```\n\n\n2. To verify that the guestbook service is up, list the services you created in the cluster with the `kubectl get services` command:\n\n    ```console\n    $ kubectl get services\n    NAME              CLUSTER_IP       EXTERNAL_IP       PORT(S)       SELECTOR               AGE\n    guestbook         10.0.217.218     146.148.81.8      3000/TCP      app=guestbook          1h\n    redis-master      10.0.136.3       \u003cnone\u003e            6379/TCP      app=redis,role=master  1h\n    redis-slave       10.0.21.92       \u003cnone\u003e            6379/TCP      app-redis,role=slave   1h\n    ...\n    ```\n\n    Result: The service is created with label `app=guestbook`.\n\n### Step Seven: View the guestbook \u003ca id=\"step-seven\"\u003e\u003c/a\u003e\n\nYou can now play with the guestbook that you just created by opening it in a browser (it might take a few moments for the guestbook to come up).\n\n * **Service Port Forward:**\n    It should be a trick to connect to guestbook running in a Kubernetes cluster\n  \n  ```console\n  $ kubectl port-forward svc/guestbook 3000:3000\n  Forwarding from 127.0.0.1:3000 -\u003e 3000\n  Forwarding from [::1]:3000 -\u003e 3000\n  ```\n  \n More info: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/\n\n To view the guestbook, navigate to `http://localhost:3000` in your browser.\n\n### Installing KubeApps\n```console\n$ curl -fsSL https://raw.githubusercontent.com/fishworks/gofish/master/scripts/install.sh | bash\n$ gofish init\n$ gofish install helm\n$ helm repo add bitnami https://charts.bitnami.com/bitnami\n$ helm init\n$ helm install --name kubeapps --namespace kubeapps bitnami/kubeapps\n$ kubectl create serviceaccount kubeapps-operator\n$ kubectl create clusterrolebinding kubeapps-operator --clusterrole=cluster-admin --serviceaccount=default:kubeapps-operator\n$ kubectl get secret $(kubectl get serviceaccount kubeapps-operator -o jsonpath='{.secrets[].name}') -o jsonpath='{.data.token}' | base64 --decode\\n\n$ kubectl port-forward --namespace kubeapps svc/kubeapps 8080:80\n```\n\n * **Service Port Forward:**\n    It should be a trick to connect to KubeApps running in a Kubernetes cluster\n  \n  ```console\n  $ kubectl port-forward --namespace kubeapps svc/kubeapps 8080:80\n  Forwarding from 127.0.0.1:8080 -\u003e 8080\n  Forwarding from [::1]:8080 -\u003e 8080\n  ```\n To view the KubeApps, navigate to `http://localhost:8080` in your browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardsonlima%2Fkubernetes-docker-in-docker-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichardsonlima%2Fkubernetes-docker-in-docker-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardsonlima%2Fkubernetes-docker-in-docker-cluster/lists"}