Skip to content

Commit 0701737

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#36373 from vwfs/kubeadm_fix_centos_ssl
Automatic merge from submit-queue (batch tested with PRs 37366, 36373) kubeadm: Let apiserver and controller-manager host-mount /etc/pki when required #<!-- 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**: This PR checks if /etc/pki is present on the host machine and adds a host-mount to the apiserver and controller-manager manifest if required. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes#36150 **Special notes for your reviewer**: **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 Fix incompatible host mounts for SSL certificates when deploying on CentOS with kubeadm ```
2 parents 1552edb + fd8e6d0 commit 0701737

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

cmd/kubeadm/app/master/manifests.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,37 @@ const (
5454
// WriteStaticPodManifests builds manifest objects based on user provided configuration and then dumps it to disk
5555
// where kubelet will pick and schedule them.
5656
func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
57+
volumes := []api.Volume{k8sVolume(cfg)}
58+
volumeMounts := []api.VolumeMount{k8sVolumeMount()}
59+
60+
if isCertsVolumeMountNeeded() {
61+
volumes = append(volumes, certsVolume(cfg))
62+
volumeMounts = append(volumeMounts, certsVolumeMount())
63+
}
64+
65+
if isPkiVolumeMountNeeded() {
66+
volumes = append(volumes, pkiVolume(cfg))
67+
volumeMounts = append(volumeMounts, pkiVolumeMount())
68+
}
69+
5770
// Prepare static pod specs
5871
staticPodSpecs := map[string]api.Pod{
5972
kubeAPIServer: componentPod(api.Container{
6073
Name: kubeAPIServer,
6174
Image: images.GetCoreImage(images.KubeAPIServerImage, cfg, kubeadmapi.GlobalEnvParams.HyperkubeImage),
6275
Command: getAPIServerCommand(cfg),
63-
VolumeMounts: []api.VolumeMount{certsVolumeMount(), k8sVolumeMount()},
76+
VolumeMounts: volumeMounts,
6477
LivenessProbe: componentProbe(8080, "/healthz"),
6578
Resources: componentResources("250m"),
66-
}, certsVolume(cfg), k8sVolume(cfg)),
79+
}, volumes...),
6780
kubeControllerManager: componentPod(api.Container{
6881
Name: kubeControllerManager,
6982
Image: images.GetCoreImage(images.KubeControllerManagerImage, cfg, kubeadmapi.GlobalEnvParams.HyperkubeImage),
7083
Command: getControllerManagerCommand(cfg),
71-
VolumeMounts: []api.VolumeMount{certsVolumeMount(), k8sVolumeMount()},
84+
VolumeMounts: volumeMounts,
7285
LivenessProbe: componentProbe(10252, "/healthz"),
7386
Resources: componentResources("200m"),
74-
}, certsVolume(cfg), k8sVolume(cfg)),
87+
}, volumes...),
7588
kubeScheduler: componentPod(api.Container{
7689
Name: kubeScheduler,
7790
Image: images.GetCoreImage(images.KubeSchedulerImage, cfg, kubeadmapi.GlobalEnvParams.HyperkubeImage),
@@ -141,6 +154,12 @@ func etcdVolumeMount() api.VolumeMount {
141154
}
142155
}
143156

157+
func isCertsVolumeMountNeeded() bool {
158+
// Always return true for now. We may add conditional logic here for images which do not require host mounting /etc/ssl
159+
// hyperkube for example already has valid ca-certificates installed
160+
return true
161+
}
162+
144163
// certsVolume exposes host SSL certificates to pod containers.
145164
func certsVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
146165
return api.Volume{
@@ -159,9 +178,35 @@ func certsVolumeMount() api.VolumeMount {
159178
}
160179
}
161180

162-
func k8sVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
181+
func isPkiVolumeMountNeeded() bool {
182+
// On some systems were we host-mount /etc/ssl/certs, it is also required to mount /etc/pki. This is needed
183+
// due to symlinks pointing from files in /etc/ssl/certs into /etc/pki/
184+
if _, err := os.Stat("/etc/pki"); err == nil {
185+
return true
186+
}
187+
return false
188+
}
189+
190+
func pkiVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
163191
return api.Volume{
164192
Name: "pki",
193+
VolumeSource: api.VolumeSource{
194+
// TODO(phase1+) make path configurable
195+
HostPath: &api.HostPathVolumeSource{Path: "/etc/pki"},
196+
},
197+
}
198+
}
199+
200+
func pkiVolumeMount() api.VolumeMount {
201+
return api.VolumeMount{
202+
Name: "pki",
203+
MountPath: "/etc/pki",
204+
}
205+
}
206+
207+
func k8sVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
208+
return api.Volume{
209+
Name: "k8s",
165210
VolumeSource: api.VolumeSource{
166211
HostPath: &api.HostPathVolumeSource{Path: kubeadmapi.GlobalEnvParams.KubernetesDir},
167212
},
@@ -170,7 +215,7 @@ func k8sVolume(cfg *kubeadmapi.MasterConfiguration) api.Volume {
170215

171216
func k8sVolumeMount() api.VolumeMount {
172217
return api.VolumeMount{
173-
Name: "pki",
218+
Name: "k8s",
174219
MountPath: "/etc/kubernetes/",
175220
ReadOnly: true,
176221
}

cmd/kubeadm/app/master/manifests_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestK8sVolume(t *testing.T) {
201201
{
202202
cfg: &kubeadmapi.MasterConfiguration{},
203203
expected: api.Volume{
204-
Name: "pki",
204+
Name: "k8s",
205205
VolumeSource: api.VolumeSource{
206206
HostPath: &api.HostPathVolumeSource{
207207
Path: kubeadmapi.GlobalEnvParams.KubernetesDir},
@@ -234,7 +234,7 @@ func TestK8sVolumeMount(t *testing.T) {
234234
}{
235235
{
236236
expected: api.VolumeMount{
237-
Name: "pki",
237+
Name: "k8s",
238238
MountPath: "/etc/kubernetes/",
239239
ReadOnly: true,
240240
},

0 commit comments

Comments
 (0)