Production-Grade Container Scheduling and Management
Go to file
Kubernetes Submit Queue b4f8d88d51 Merge pull request #35843 from bulletRush/feature/pre-hostname-check
Automatic merge from submit-queue

[kubeadm] pre-flight check hostname to ensure kubelet can launch static pods li…

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md
2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md
3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes
-->

**What this PR does / why we need it**: pre-flight check hostname to ensure kubelet can launch static pods like kube-apiserver/kube-controller-manager

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # 

**Special notes for your reviewer**:

# what is the influence of this issue?

kubelet will not create api server and kcm pod if your hostname is uncorrect. It complain the config files in "/etc/kubernetes/manifests" are invlid.

# how to reproduce this issue?

change your hostname by `hostnamectl set-hostname vm_81_12_centos`. then run `kubeadm init`. you will get this error log from kubelet:

```log
Oct 27 11:12:57 vm_81_12_centos kubelet: I1027 11:12:57.279458    2695 file.go:123] Can't process config file "/etc/kubernetes/manifests/kube-controller-manager.json": invalid pod: [metadata.name: Invalid value: "kube-controller-manager-vm_81_12_centos": must match the regex [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)* (e.g. 'example.com') spec.nodeName: Invalid value: "vm_81_12_centos": must match the regex [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)* (e.g. 'example.com')]
```

# where the error comes from in the code?

`pkg/kubelet/config/file.go:144 sourceFile:extractFromDir`

```go
func (s *sourceFile) extractFromDir(name string) ([]*api.Pod, error) {
	dirents, err := filepath.Glob(filepath.Join(name, "[^.]*"))
	if err != nil {
		return nil, fmt.Errorf("glob failed: %v", err)
	}

	pods := make([]*api.Pod, 0)
	if len(dirents) == 0 {
		return pods, nil
	}

	sort.Strings(dirents)
	for _, path := range dirents {
		statInfo, err := os.Stat(path)
		if err != nil {
			glog.V(1).Infof("Can't get metadata for %q: %v", path, err)
			continue
		}

		switch {
		case statInfo.Mode().IsDir():
			glog.V(1).Infof("Not recursing into config path %q", path)
		case statInfo.Mode().IsRegular():
			pod, err := s.extractFromFile(path)
			if err != nil {
-->				glog.V(1).Infof("Can't process config file %q: %v", path, err)
			} else {
				pods = append(pods, pod)
			}
		default:
			glog.V(1).Infof("Config path %q is not a directory or file: %v", path, statInfo.Mode())
		}
	}
	return pods, nil
}
```

# how to fix it?

1. change hostname by `hostnamectl set-hostname <right host name>` or
2. add `hostnameOverride` config. If hostnameOverride is set, then kubelet will use this value instead of system hostname.

**Release note**:
<!--  Steps to write your release note:
1. Use the release-note-* labels to set the release note state (if you have access) 
2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. 
-->
```release-note
```

…ke kube-apiserver/kube-controller-manager and so on.
2016-10-30 09:56:25 -07:00
.github
api Merge pull request #35390 from kargakis/update-eviction-comment 2016-10-30 03:53:19 -07:00
build-tools Merge pull request #35694 from wojtek-t/update_etcd_3_0_13 2016-10-29 05:00:55 -07:00
cluster Merge pull request #35708 from wojtek-t/rename_test_etcd_version 2016-10-29 05:46:51 -07:00
cmd Merge pull request #35843 from bulletRush/feature/pre-hostname-check 2016-10-30 09:56:25 -07:00
contrib promote contrib/mesos to incubator 2016-09-28 10:58:09 -04:00
docs Merge pull request #35390 from kargakis/update-eviction-comment 2016-10-30 03:53:19 -07:00
examples include multiple versions in clientset 2016-10-29 13:30:47 -07:00
federation include multiple versions in clientset 2016-10-29 13:30:47 -07:00
Godeps Merge pull request #35694 from wojtek-t/update_etcd_3_0_13 2016-10-29 05:00:55 -07:00
hack Merge pull request #35733 from mikedanese/set-gen 2016-10-30 08:43:41 -07:00
hooks Generate and verify openapi specs in source tree at api/openapi-spec 2016-09-29 17:03:31 -07:00
logo Update usage guidelines to reflect the donation to CNCF 2016-10-12 15:56:50 -07:00
pkg Merge pull request #35733 from mikedanese/set-gen 2016-10-30 08:43:41 -07:00
plugin include multiple versions in clientset 2016-10-29 13:30:47 -07:00
staging run copy.sh 2016-10-29 14:44:07 -07:00
test Merge pull request #35454 from bowei/image-for-issue-32551 2016-10-30 01:56:10 -07:00
third_party autogenerated 2016-10-21 17:32:32 -07:00
vendor run copy.sh 2016-10-29 14:44:07 -07:00
www
.generated_docs Add 'kubectl set limit' 2016-10-14 08:35:32 -04:00
.gitignore Add verbose mode to boilerplate 2016-10-22 21:40:08 -07:00
BUILD Revert "disable bazel build" 2016-10-24 14:47:26 -07:00
CHANGELOG.md Update CHANGELOG.md for v1.4.5. 2016-10-28 19:08:32 -07:00
code-of-conduct.md Change code of conduct to call CNCF CoC by reference 2016-10-19 13:22:35 -04:00
CONTRIB.md
CONTRIBUTING.md Beef up the CONTRIBUTING doc 2016-10-26 00:08:33 +02:00
DESIGN.md
labels.yaml Updating labels.yaml to add labels: cncf-cla:yes and cncf-cla:no 2016-10-03 09:54:42 -07:00
LICENSE
Makefile rename build/ to build-tools/ 2016-10-24 14:41:56 -07:00
Makefile.generated_files Make all useage of sort deterministic 2016-10-20 16:47:20 -04:00
OWNERS Add jbeda to top level OWNERS 2016-10-25 13:08:07 -07:00
README.md Add community expectations about conduct and reviewing. 2016-09-30 15:35:15 +00:00
Vagrantfile
WORKSPACE gazel 2016-10-21 17:31:54 -07:00

Kubernetes

Submit Queue Widget GoDoc Widget Coverage Status Widget

Are you ...


Kubernetes is an open source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployment, maintenance, and scaling of applications.

Kubernetes is:

  • lean: lightweight, simple, accessible
  • portable: public, private, hybrid, multi cloud
  • extensible: modular, pluggable, hookable, composable
  • self-healing: auto-placement, auto-restart, auto-replication

Kubernetes builds upon a decade and a half of experience at Google running production workloads at scale, combined with best-of-breed ideas and practices from the community.


Kubernetes is ready for Production!

With the 1.0.1 release Kubernetes is ready to serve your production workloads.

Kubernetes can run anywhere!

You can run Kubernetes on your local workstation under Vagrant, cloud providers (e.g. GCE, AWS, Azure), and physical hardware. Essentially, anywhere Linux runs you can run Kubernetes. Checkout the Getting Started Guides for details.

Concepts

Kubernetes works with the following concepts:

Cluster
A cluster is a set of physical or virtual machines and other infrastructure resources used by Kubernetes to run your applications. Kubernetes can run anywhere! See the Getting Started Guides for instructions for a variety of services.
Node
A node is a physical or virtual machine running Kubernetes, onto which pods can be scheduled.
Pod
Pods are a colocated group of application containers with shared volumes. They're the smallest deployable units that can be created, scheduled, and managed with Kubernetes. Pods can be created individually, but it's recommended that you use a replication controller even if creating a single pod.
Replication controller
Replication controllers manage the lifecycle of pods. They ensure that a specified number of pods are running at any given time, by creating or killing pods as required.
Service
Services provide a single, stable name and address for a set of pods. They act as basic load balancers.
Label
Labels are used to organize and select groups of objects based on key:value pairs.

Documentation

Kubernetes documentation is organized into several categories.

Community, discussion, contribution, and support

See which companies are committed to driving quality in Kubernetes on our community page.

Do you want to help "shape the evolution of technologies that are container packaged, dynamically scheduled and microservices oriented?"

You should consider joining the Cloud Native Computing Foundation. For details about who's involved and how Kubernetes plays a role, read their announcement.

Code of conduct

Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.

Are you ready to add to the discussion?

We have presence on:

You can also view recordings of past events and presentations on our Media page.

For Q&A, our threads are at:

Want to contribute to Kubernetes?

If you're interested in being a contributor and want to get involved in developing Kubernetes, start in the Kubernetes Developer Guide and also review the contributor guidelines.

Or, if you just have an idea for a new feature, see the Kubernetes Features repository for details on how to propose it.

Also, please see our expectations for members of the Kubernetes community.

Support

While there are many different channels that you can use to get ahold of us, you can help make sure that we are efficient in getting you the help that you need.

If you need support, start with the troubleshooting guide and work your way through the process that we've outlined.

That said, if you have questions, reach out to us one way or another. We don't bite!

Community resources

You can find more projects, tools and articles related to Kubernetes on the awesome-kubernetes list. Add your project there and help us make it better.

Instructive & educational resources for the Kubernetes community. By the community.

  • Community Documentation

Here you can learn more about the current happenings in the kubernetes community.

Analytics