설치

Edit This Page

맨 처음부터 사용자 지정 클러스터 생성

This guide is for people who want to craft a custom Kubernetes cluster. If you can find an existing Getting Started Guide that meets your needs on this list, then we recommend using it, as you will be able to benefit from the experience of others. However, if you have specific IaaS, networking, configuration management, or operating system requirements not met by any of those guides, then this guide will provide an outline of the steps you need to take. Note that it requires considerably more effort than using one of the pre-defined guides.

This guide is also useful for those wanting to understand at a high level some of the steps that existing cluster setup scripts are making.

설계 및 준비

학습 계획

  1. You should be familiar with using Kubernetes already. We suggest you set up a temporary cluster by following one of the other Getting Started Guides. This will help you become familiar with the CLI (kubectl) and concepts (pods, services, etc.) first.
  2. You should have kubectl installed on your desktop. This will happen as a side effect of completing one of the other Getting Started Guides. If not, follow the instructions here.

클라우드 공급자

Kubernetes has the concept of a Cloud Provider, which is a module which provides an interface for managing TCP Load Balancers, Nodes (Instances) and Networking Routes. The interface is defined in pkg/cloudprovider/cloud.go. It is possible to create a custom cluster without implementing a cloud provider (for example if using bare-metal), and not all parts of the interface need to be implemented, depending on how flags are set on various components.

노드

네트워크

네트워크 연결

Kubernetes has a distinctive networking model.

Kubernetes allocates an IP address to each pod. When creating a cluster, you need to allocate a block of IPs for Kubernetes to use as Pod IPs. The simplest approach is to allocate a different block of IPs to each node in the cluster as the node is added. A process in one pod should be able to communicate with another pod using the IP of the second pod. This connectivity can be accomplished in two ways:

Which method you choose depends on your environment and requirements. There are various ways to implement one of the above options:

You will need to select an address range for the Pod IPs.

Kubernetes also allocates an IP to each service. However, service IPs do not necessarily need to be routable. The kube-proxy takes care of translating Service IPs to Pod IPs before traffic leaves the node. You do need to allocate a block of IPs for services. Call this SERVICE_CLUSTER_IP_RANGE. For example, you could set SERVICE_CLUSTER_IP_RANGE="10.0.0.0/16", allowing 65534 distinct services to be active at once. Note that you can grow the end of this range, but you cannot move it without disrupting the services and pods that already use it.

Also, you need to pick a static IP for master node.

네트워크 폴리시

Kubernetes enables the definition of fine-grained network policy between Pods using the NetworkPolicy resource.

Not all networking providers support the Kubernetes NetworkPolicy API, see Using Network Policy for more information.

클러스터 이름 구성

You should pick a name for your cluster. Pick a short name for each cluster which is unique from future cluster names. This will be used in several ways:

소프트웨어 바이너리

You will need binaries for:

쿠버네티스 바이너리 다운로드 및 압축 해제

A Kubernetes binary release includes all the Kubernetes binaries as well as the supported release of etcd. You can use a Kubernetes binary release (recommended) or build your Kubernetes binaries following the instructions in the Developer Documentation. Only using a binary release is covered in this guide.

Download the latest binary release and unzip it. Server binary tarballs are no longer included in the Kubernetes final tarball, so you will need to locate and run ./kubernetes/cluster/get-kube-binaries.sh to download and extract the client and server binaries. Then locate ./kubernetes/server/bin, which contains all the necessary binaries.

이미지 선택

You will run docker, kubelet, and kube-proxy outside of a container, the same way you would run any system daemon, so you just need the bare binaries. For etcd, kube-apiserver, kube-controller-manager, and kube-scheduler, we recommend that you run these as containers, so you need an image to be built.

You have several choices for Kubernetes images:

We recommend that you use the etcd version which is provided in the Kubernetes binary distribution. The Kubernetes binaries in the release were tested extensively with this version of etcd and not with any other version. The recommended version number can also be found as the value of TAG in kubernetes/cluster/images/etcd/Makefile.

For the minimum recommended version of etcd, refer to Configuring and Updating etcd

The remainder of the document assumes that the image identifiers have been chosen and stored in corresponding env vars. Examples (replace with latest tags and appropriate registry):

보안 모델

There are two main options for security:

If following the HTTPS approach, you will need to prepare certs and credentials.

인증서 준비

You need to prepare several certs:

Unless you plan to have a real CA generate your certs, you will need to generate a root cert and use that to sign the master, kubelet, and kubectl certs. How to do this is described in the authentication documentation.

You will end up with the following files (we will use these variables later on)

자격 증명 준비

The admin user (and any users) need:

Your tokens and passwords need to be stored in a file for the apiserver to read. This guide uses /var/lib/kube-apiserver/known_tokens.csv. The format for this file is described in the authentication documentation.

For distributing credentials to clients, the convention in Kubernetes is to put the credentials into a kubeconfig file.

The kubeconfig file for the administrator can be created as follows:

Next, make a kubeconfig file for the kubelets and kube-proxy. There are a couple of options for how many distinct files to make:

  1. Use the same credential as the admin
    • This is simplest to setup.
  2. One token and kubeconfig file for all kubelets, one for all kube-proxy, one for admin.
    • This mirrors what is done on GCE today
  3. Different credentials for every kubelet, etc.
    • We are working on this but all the pieces are not ready yet.

You can make the files by copying the $HOME/.kube/config or by using the following template:

apiVersion: v1
kind: Config
users:
- name: kubelet
  user:
    token: ${KUBELET_TOKEN}
clusters:
- name: local
  cluster:
    certificate-authority: /srv/kubernetes/ca.crt
contexts:
- context:
    cluster: local
    user: kubelet
  name: service-account-context
current-context: service-account-context

Put the kubeconfig(s) on every node. The examples later in this guide assume that there are kubeconfigs in /var/lib/kube-proxy/kubeconfig and /var/lib/kubelet/kubeconfig.

노드의 기본 소프트웨어 구성 및 설치

This section discusses how to configure machines to be Kubernetes nodes.

You should run three daemons on every node:

You will also need to do assorted other configuration on top of a base OS install.

Tip: One possible starting point is to setup a cluster using an existing Getting Started Guide. After getting a cluster running, you can then copy the init.d scripts or systemd unit files from that cluster, and then modify them for use on your custom cluster.

Docker

The minimum required Docker version will vary as the kubelet version changes. The newest stable release is a good choice. Kubelet will log a warning and refuse to start pods if the version is too old, so pick a version and try it.

If you previously had Docker installed on a node without setting Kubernetes-specific options, you may have a Docker-created bridge and iptables rules. You may want to remove these as follows before proceeding to configure Docker for Kubernetes.

iptables -t nat -F
ip link set docker0 down
ip link delete docker0

The way you configure docker will depend in whether you have chosen the routable-vip or overlay-network approaches for your network. Some suggested docker options:

You may want to increase the number of open files for docker:

Where this config goes depends on your node OS. For example, GCE’s Debian-based distro uses /etc/default/docker.

Ensure docker is working correctly on your system before proceeding with the rest of the installation, by following examples given in the Docker documentation.

rkt

rkt is an alternative to Docker. You only need to install one of Docker or rkt. The minimum version required is v0.5.6.

systemd is required on your node to run rkt. The minimum version required to match rkt v0.5.6 is systemd 215.

rkt metadata service is also required for rkt networking support. You can start rkt metadata service by using command like sudo systemd-run rkt metadata-service

Then you need to configure your kubelet with flag:

kubelet

All nodes should run kubelet. See Software Binaries.

Arguments to consider:

kube-proxy

All nodes should run kube-proxy. (Running kube-proxy on a “master” node is not strictly required, but being consistent is easier.) Obtain a binary as described for kubelet.

Arguments to consider:

Note that on some Linux platforms, you may need to manually install the conntrack package which is a dependency of kube-proxy, or else kube-proxy cannot be started successfully.

For more details about debugging kube-proxy problems, refer to Debug Services

네트워킹

Each node needs to be allocated its own CIDR range for pod networking. Call this NODE_X_POD_CIDR.

A bridge called cbr0 needs to be created on each node. The bridge is explained further in the networking documentation. The bridge itself needs an address from $NODE_X_POD_CIDR - by convention the first IP. Call this NODE_X_BRIDGE_ADDR. For example, if NODE_X_POD_CIDR is 10.0.0.0/16, then NODE_X_BRIDGE_ADDR is 10.0.0.1/16. NOTE: this retains the /16 suffix because of how this is used later.

If you have turned off Docker’s IP masquerading to allow pods to talk to each other, then you may need to do masquerading just for destination IPs outside the cluster network. For example:

iptables -t nat -A POSTROUTING ! -d ${CLUSTER_SUBNET} -m addrtype ! --dst-type LOCAL -j MASQUERADE

This will rewrite the source address from the PodIP to the Node IP for traffic bound outside the cluster, and kernel connection tracking will ensure that responses destined to the node still reach the pod.

NOTE: This is environment specific. Some environments will not need any masquerading at all. Others, such as GCE, will not allow pod IPs to send traffic to the internet, but have no problem with them inside your GCE Project.

기타

구성 관리 사용

The previous steps all involved “conventional” system administration techniques for setting up machines. You may want to use a Configuration Management system to automate the node configuration process. There are examples of Ansible, Juju, and CoreOS Cloud Config in the various Getting Started Guides.

클러스터 부트스트랩

While the basic node services (kubelet, kube-proxy, docker) are typically started and managed using traditional system administration/automation approaches, the remaining master components of Kubernetes are all configured and managed by Kubernetes:

etcd

You will need to run one or more instances of etcd.

See cluster-troubleshooting for more discussion on factors affecting cluster availability.

To run an etcd instance:

  1. Copy cluster/gce/manifests/etcd.manifest
  2. Make any modifications needed
  3. Start the pod by putting it into the kubelet manifest directory

API 서버, 컨트롤러 관리자, 스케줄러

The apiserver, controller manager, and scheduler will each run as a pod on the master node.

For each of these components, the steps to start them running are similar:

  1. Start with a provided template for a pod.
  2. Set the HYPERKUBE_IMAGE to the values chosen in Selecting Images.
  3. Determine which flags are needed for your cluster, using the advice below each template.
  4. Set the flags to be individual strings in the command array (for example $ARGN below)
  5. Start the pod by putting the completed template into the kubelet manifest directory.
  6. Verify that the pod is started.

API 서버 파드 템플릿

{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "kube-apiserver"
  },
  "spec": {
    "hostNetwork": true,
    "containers": [
      {
        "name": "kube-apiserver",
        "image": "${HYPERKUBE_IMAGE}",
        "command": [
          "/hyperkube",
          "apiserver",
          "$ARG1",
          "$ARG2",
          ...
          "$ARGN"
        ],
        "ports": [
          {
            "name": "https",
            "hostPort": 443,
            "containerPort": 443
          },
          {
            "name": "local",
            "hostPort": 8080,
            "containerPort": 8080
          }
        ],
        "volumeMounts": [
          {
            "name": "srvkube",
            "mountPath": "/srv/kubernetes",
            "readOnly": true
          },
          {
            "name": "etcssl",
            "mountPath": "/etc/ssl",
            "readOnly": true
          }
        ],
        "livenessProbe": {
          "httpGet": {
            "scheme": "HTTP",
            "host": "127.0.0.1",
            "port": 8080,
            "path": "/healthz"
          },
          "initialDelaySeconds": 15,
          "timeoutSeconds": 15
        }
      }
    ],
    "volumes": [
      {
        "name": "srvkube",
        "hostPath": {
          "path": "/srv/kubernetes"
        }
      },
      {
        "name": "etcssl",
        "hostPath": {
          "path": "/etc/ssl"
        }
      }
    ]
  }
}

Here are some apiserver flags you may need to set:

If you are following the firewall-only security approach, then use these arguments:

If you are using the HTTPS approach, then set:

This pod mounts several node file system directories using the hostPath volumes. Their purposes are:

TODO document proxy-ssh setup.

클라우드 공급자

Apiserver supports several cloud providers.

Some cloud providers require a config file. If so, you need to put config file into apiserver image or mount through hostPath.

스케줄러 파드 템플릿

Complete this template for the scheduler pod:

{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "kube-scheduler"
  },
  "spec": {
    "hostNetwork": true,
    "containers": [
      {
        "name": "kube-scheduler",
        "image": "$HYPERKUBE_IMAGE",
        "command": [
          "/hyperkube",
          "scheduler",
          "--master=127.0.0.1:8080",
          "$SCHEDULER_FLAG1",
          ...
          "$SCHEDULER_FLAGN"
        ],
        "livenessProbe": {
          "httpGet": {
            "scheme": "HTTP",
            "host": "127.0.0.1",
            "port": 10251,
            "path": "/healthz"
          },
          "initialDelaySeconds": 15,
          "timeoutSeconds": 15
        }
      }
    ]
  }
}

Typically, no additional flags are required for the scheduler.

Optionally, you may want to mount /var/log as well and redirect output there.

컨트롤러 관리자 템플릿

Template for controller manager pod:

{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "kube-controller-manager"
  },
  "spec": {
    "hostNetwork": true,
    "containers": [
      {
        "name": "kube-controller-manager",
        "image": "$HYPERKUBE_IMAGE",
        "command": [
          "/hyperkube",
          "controller-manager",
          "$CNTRLMNGR_FLAG1",
          ...
          "$CNTRLMNGR_FLAGN"
        ],
        "volumeMounts": [
          {
            "name": "srvkube",
            "mountPath": "/srv/kubernetes",
            "readOnly": true
          },
          {
            "name": "etcssl",
            "mountPath": "/etc/ssl",
            "readOnly": true
          }
        ],
        "livenessProbe": {
          "httpGet": {
            "scheme": "HTTP",
            "host": "127.0.0.1",
            "port": 10252,
            "path": "/healthz"
          },
          "initialDelaySeconds": 15,
          "timeoutSeconds": 15
        }
      }
    ],
    "volumes": [
      {
        "name": "srvkube",
        "hostPath": {
          "path": "/srv/kubernetes"
        }
      },
      {
        "name": "etcssl",
        "hostPath": {
          "path": "/etc/ssl"
        }
      }
    ]
  }
}

Flags to consider using with controller manager:

API 서버, 스케줄러, 컨트롤러 관리자 시작 및 확인

Place each completed pod template into the kubelet config dir (whatever --config= argument of kubelet is set to, typically /etc/kubernetes/manifests). The order does not matter: scheduler and controller manager will retry reaching the apiserver until it is up.

Use ps or docker ps to verify that each process has started. For example, verify that kubelet has started a container for the apiserver like this:

$ sudo docker ps | grep apiserver
5783290746d5        k8s.gcr.io/kube-apiserver:e36bf367342b5a80d7467fd7611ad873            "/bin/sh -c '/usr/lo'"    10 seconds ago      Up 9 seconds                              k8s_kube-apiserver.feb145e7_kube-apiserver-kubernetes-master_default_eaebc600cf80dae59902b44225f2fc0a_225a4695

Then try to connect to the apiserver:

$ echo $(curl -s http://localhost:8080/healthz)
ok
$ curl -s http://localhost:8080/api
{
  "versions": [
    "v1"
  ]
}

If you have selected the --register-node=true option for kubelets, they will now begin self-registering with the apiserver. You should soon be able to see all your nodes by running the kubectl get nodes command. Otherwise, you will need to manually create node objects.

클러스터 서비스 시작

You will want to complete your Kubernetes clusters by adding cluster-wide services. These are sometimes called addons, and an overview of their purpose is in the admin guide.

Notes for setting up each cluster service are given below:

문제 해결

validate-cluster 명령 실행

cluster/validate-cluster.sh is used by cluster/kube-up.sh to determine if the cluster start succeeded.

Example usage and output:

KUBECTL_PATH=$(which kubectl) NUM_NODES=3 KUBERNETES_PROVIDER=local cluster/validate-cluster.sh
Found 3 node(s).
NAME                    STATUS    AGE     VERSION
node1.local             Ready     1h      v1.6.9+a3d1dfa6f4335
node2.local             Ready     1h      v1.6.9+a3d1dfa6f4335
node3.local             Ready     1h      v1.6.9+a3d1dfa6f4335
Validate output:
NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok
scheduler            Healthy   ok
etcd-1               Healthy   {"health": "true"}
etcd-2               Healthy   {"health": "true"}
etcd-0               Healthy   {"health": "true"}
Cluster validation succeeded

파드와 서비스 검사

Try to run through the “Inspect your cluster” section in one of the other Getting Started Guides, such as GCE. You should see some services. You should also see “mirror pods” for the apiserver, scheduler and controller-manager, plus any add-ons you started.

예제 실행하기

At this point you should be able to run through one of the basic examples, such as the nginx example.

적합성 테스트 실행

You may want to try to run the Conformance test. Any failures may give a hint as to areas that need more attention.

네트워킹

The nodes must be able to connect to each other using their private IP. Verify this by pinging or SSH-ing from one node to another.

도움말 얻기

If you run into trouble, see the section on troubleshooting, post to the Kubernetes Forum, or come ask questions on Slack.

지원 레벨

IaaS Provider Config. Mgmt OS Networking Docs Conforms Support Level
any any any any docs Community (@erictune)

For support level information on all solutions, see the Table of solutions chart.

피드백