allow kubectl to be built statically
* Package kubectl in a container * Add example with a pod using kubectl as a sidecar
This commit is contained in:
		
							parent
							
								
									5131e2af64
								
							
						
					
					
						commit
						c727aa3202
					
				| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					kubectl
 | 
				
			||||||
 | 
					.tag
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					# Copyright 2014 Google Inc. All rights reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					# you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					# You may obtain a copy of the License at
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#     http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					# distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					# See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					# limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FROM scratch
 | 
				
			||||||
 | 
					MAINTAINER Daniel Smith <dbsmith@google.com>
 | 
				
			||||||
 | 
					ADD kubectl kubectl
 | 
				
			||||||
 | 
					ENTRYPOINT ["/kubectl"]
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					# Use:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# `make kubectl` will build kubectl.
 | 
				
			||||||
 | 
					# `make tag` will suggest a tag.
 | 
				
			||||||
 | 
					# `make container` will build a container-- you must supply a tag.
 | 
				
			||||||
 | 
					# `make push` will push the container-- you must supply a tag.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					kubectl:
 | 
				
			||||||
 | 
						KUBE_STATIC_OVERRIDES="kubectl" ../../hack/build-go.sh cmd/kubectl; cp ../../_output/local/bin/linux/amd64/kubectl .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.tag: kubectl
 | 
				
			||||||
 | 
						./kubectl version -c | grep -o 'GitVersion:"[^"]*"' | cut -f 2 -d '"' > .tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tag: .tag
 | 
				
			||||||
 | 
						@echo "Suggest using TAG=$(shell cat .tag)"
 | 
				
			||||||
 | 
						@echo "$$ make container TAG=$(shell cat .tag)"
 | 
				
			||||||
 | 
						@echo "or"
 | 
				
			||||||
 | 
						@echo "$$ make push TAG=$(shell cat .tag)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					container:
 | 
				
			||||||
 | 
						$(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion))
 | 
				
			||||||
 | 
						docker build -t gcr.io/google_containers/kubectl:$(TAG) .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					push: container
 | 
				
			||||||
 | 
						$(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion))
 | 
				
			||||||
 | 
						gcloud preview docker push gcr.io/google_containers/kubectl:$(TAG)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						rm -f kubectl
 | 
				
			||||||
 | 
						rm -f .tag
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					This directory contains a Dockerfile and Makefile for packaging up kubectl into
 | 
				
			||||||
 | 
					a container.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					It's not currently automated as part of a release process, so for the moment
 | 
				
			||||||
 | 
					this is an example of what to do if you want to package kubectl into a
 | 
				
			||||||
 | 
					container/your pod.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					In the future, we may release consistently versioned groups of containers when
 | 
				
			||||||
 | 
					we cut a release, in which case the source of gcr.io/google_containers/kubectl
 | 
				
			||||||
 | 
					would become that automated process.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```pod.json``` is provided as an example of packaging kubectl as a sidecar
 | 
				
			||||||
 | 
					container, and to help you verify that kubectl works correctly in
 | 
				
			||||||
 | 
					this configuration.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A possible reason why you would want to do this is to use ```kubectl proxy``` as
 | 
				
			||||||
 | 
					a drop-in replacement for the old no-auth KUBERNETES_RO service. The other
 | 
				
			||||||
 | 
					containers in your pod will find the proxy apparently serving on localhost.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[]()
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "kind": "Pod",
 | 
				
			||||||
 | 
					  "apiVersion": "v1beta3",
 | 
				
			||||||
 | 
					  "metadata": {
 | 
				
			||||||
 | 
					    "name": "kubectl-tester"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "spec": {
 | 
				
			||||||
 | 
					    "containers": [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "bb",
 | 
				
			||||||
 | 
					        "image": "gcr.io/google_containers/busybox",
 | 
				
			||||||
 | 
					        "command": [
 | 
				
			||||||
 | 
					          "sh", "-c", "sleep 5; wget -O - ${KUBERNETES_RO_SERVICE_HOST}:${KUBERNETES_RO_SERVICE_PORT}/api/v1beta3/pods/; sleep 10000"
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "ports": [
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "containerPort": 8080,
 | 
				
			||||||
 | 
					            "protocol": "TCP"
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "env": [
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "name": "KUBERNETES_RO_SERVICE_HOST",
 | 
				
			||||||
 | 
					            "value": "127.0.0.1"
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "name": "KUBERNETES_RO_SERVICE_PORT",
 | 
				
			||||||
 | 
					            "value": "8001"
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "volumeMounts": [
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "name": "test-volume",
 | 
				
			||||||
 | 
					            "mountPath": "/mount/test-volume"
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "kubectl",
 | 
				
			||||||
 | 
					        "image": "gcr.io/google_containers/kubectl:v0.18.0-120-gaeb4ac55ad12b1-dirty",
 | 
				
			||||||
 | 
					        "imagePullPolicy": "Always",
 | 
				
			||||||
 | 
					        "args": [
 | 
				
			||||||
 | 
					          "proxy", "-p", "8001"
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "volumes": [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "name": "test-volume",
 | 
				
			||||||
 | 
					        "emptyDir": {}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue