Check this snippet out for how I set up my cluster: https://gitlab.com/snippets/1674542
I’m on gitlab 9.5.4, Kubernetes 1.6.9, and attempting to use the following Dockerfile and .gitlab-ci.yml to deploy a static website from gitlab
Dockerfile:
# This file is a template, and might need editing before it works on your project.
FROM httpd:alpine
RUN rm -rf srcimages
COPY ./ /usr/local/apache2/htdocs/
.gitlab-ci.yml:
# This file is a template, and might need editing before it works on your project.
# Explanation on the scripts:
# https://gitlab.com/gitlab-examples/kubernetes-deploy/blob/master/README.md
image: registry.gitlab.com/gitlab-examples/kubernetes-deploy
variables:
# Application deployment domain
KUBE_DOMAIN: www.apps.mydomain.com
stages:
- build
- test
- review
- staging
- production
- cleanup
build:
stage: build
script:
- command build
only:
- branches
production:
stage: production
script:
- command deploy
environment:
name: production
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_DOMAIN
when: manual
only:
- master
staging:
stage: staging
script:
- command deploy
environment:
name: staging
url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_DOMAIN
only:
- master
review:
stage: review
script:
- command deploy
environment:
name: review/$CI_COMMIT_REF_NAME
url: http://$CI_PROJECT_PATH_SLUG-$CI_ENVIRONMENT_SLUG.$KUBE_DOMAIN
on_stop: stop_review
only:
- branches
except:
- master
stop_review:
stage: cleanup
variables:
GIT_STRATEGY: none
script:
- command destroy
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
when: manual
only:
- branches
except:
- master
The build step works, and I have an image posted to my container registry (127 MB!)
However, the review step fails with the following:
Running with gitlab-ci-multi-runner 9.5.0 (413da38)
on gitlab-gitlab-runner-1062866012-161mn (c9c66260)
Using Kubernetes namespace: default
Using Kubernetes executor with image registry.gitlab.com/gitlab-examples/kubernetes-deploy ...
Waiting for pod default/runner-c9c66260-project-8-concurrent-0g292k to be running, status is Pending
Waiting for pod default/runner-c9c66260-project-8-concurrent-0g292k to be running, status is Pending
Running on runner-c9c66260-project-8-concurrent-0g292k via gitlab-gitlab-runner-1062866012-161mn...
Cloning repository...
Cloning into '/web/site'...
Checking out f966e668 as auto-deploy...
Skipping Git submodules setup
$ command deploy
Reading CI_ENVIRONMENT_URL from .gitlab-ci.yml...
CI_ENVIRONMENT_URL: http://web-site-review-auto-deplo-r02mmg.www.apps.mydomain.com
Generating kubeconfig...
Cluster "gitlab-deploy" set.
User "gitlab-deploy" set.
Context "gitlab-deploy" created.
Switched to context "gitlab-deploy".
Unable to connect to the server: malformed HTTP response "\x15\x03\x01\x00\x02\x02"
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1
I looked at the source code of the Kubernetes executor’s deploy
command at https://gitlab.com/gitlab-examples/kubernetes-deploy/blob/master/deploy but I couldn’t identify what’s trying to connect to which HTTP server. The autogenerated review URL goes to “default backend - 404” and I don’t see any pods in my kubernetes cluster that correspond to the review, so I don’t know where it got hung up.