on single node kubernetes cluster i can expose a service with 'expose' cmd, but doing it via create -f <svc.json-file> fails -
i setting single node k8s cluster testing, , we've run confusing problem services. i've distilled example down 1 of deploying word press service, can kubectl create -f wordpress-rc.json followed expose. when follow create of rep controller kubectl create -f fails. show json file content below.
rep controller:
{ "kind": "replicationcontroller", "apiversion": "v1", "metadata": { "name": "wordpress", "labels": { "app": "wordpress" } }, "spec": { "replicas": 1, "selector": { "app": "wordpress" }, "template": { "metadata": { "labels": { "app": "wordpress" } }, "spec": { "containers": [ { "name": "wordpress", "image": "tutum/wordpress", "ports": [ { "containerport": 80, "name": "http-server", "protocol": "tcp" } ], "imagepullpolicy": "ifnotpresent" } ], "restartpolicy": "always", "dnspolicy": "clusterfirst" } } } }
service:
{ "kind": "service", "apiversion": "v1", "metadata": { "name": "wordpress", "labels": { "name": "wordpress" } }, "spec": { "type": "loadbalancer", "ports": [ { "name":"wordpress1", "protocol":"tcp", "port": 80, "targetport": 80 } ], "selector": { "name": "wordpress" } } }
working command sequence
alias kk kubectl kk create -f /tmp/wp-rc.json kubectl expose rc wordpress --type=loadbalancer
failed command sequence
alias kk kubectl kk create -f /tmp/wp-rc.json kk create -f /tmp/wp-service.json
my question why wouldn't service definition work, while expose command ?
for completeness.. here how start single node k8s cluster. running on centos 7, b.t.w:
# magic selinux context set command required. details, see: http://stackoverflow.com/questions/34777111/cannot-create-a-shared-volume-mount-via-emptydir-on-single-node-kubernetes-on # sudo chcon -rt svirt_sandbox_file_t /var/lib/kubelet docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data docker run \ --volume=/:/rootfs:ro \ --volume=/sys:/sys:ro \ --volume=/dev:/dev \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/var/lib/kubelet/:/var/lib/kubelet:rw \ --volume=/var/run:/var/run:rw \ --net=host \ --pid=host \ --privileged=true \ -d \ gcr.io/google_containers/hyperkube:v1.0.1 \ /hyperkube kubelet --containerized --hostname-override="127.0.0.1" --address="0.0.0.0" --api-servers=http://localhost:8080 --config=/etc/kubernetes/manifests docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v1.0.1 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2 sleep 20 # give time launch
the service json file used label selector name: wordpress
, different replication controller's label selector app: wordpress
. means service created json file targeting pods name: wordpress
label, replication controller targeting pod app: wordpress
label. why service created json file didn't work expected.
you may use kubectl svc wordpress -o yaml
compare both created services.
also, according config best practice, it's recommended create service first, , replication controller:
create service before corresponding replication controllers scheduler can spread pods comprising service. can create replication controller without specifying replicas, create service, scale replication controller, may work better in example using progressive disclosure , may have benefits in real scenarios also, such ensuring 1 replica works before creating lots of them)
Comments
Post a Comment