Services does not work in k8s (eks).
This is my k8s configuration for drone (I have an external gate with ssl for incoming connections):
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: drone-rbac
subjects:
- kind: ServiceAccount
# Reference to upper's `metadata.name`
name: default
# Reference to upper's `metadata.namespace`
namespace: default
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Service
metadata:
name: drone
spec:
selector:
role: service
app: drone
ports:
- port: 80
targetPort: http
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: drone
labels:
role: service
app: drone
spec:
replicas: 1
selector:
matchLabels:
role: service
app: drone
template:
metadata:
labels:
role: service
app: drone
spec:
nodeSelector:
role: general
containers:
- name: drone
image: drone/drone:1.0.0-rc.2
env:
- name: DRONE_KUBERNETES_ENABLED
value: "true"
- name: DRONE_KUBERNETES_NAMESPACE
value: "default"
- name: DRONE_GITHUB_SERVER
value: "https://github.com"
- name: DRONE_GITHUB_CLIENT_ID
value: "********************"
- name: DRONE_GITHUB_CLIENT_SECRET
value: "****************************************"
- name: DRONE_ORGS
value: "ticketscloud"
- name: DRONE_ADMIN
value: "zzzsochi"
- name: DRONE_OPEN
value: "true"
- name: DRONE_RPC_SECRET
value: "2443f5bb10a7004f7faa42b3d4e21f98"
- name: DRONE_SERVER_HOST
value: "drone2.******.***"
- name: DRONE_SERVER_PROTO
value: "https"
- name: DRONE_TLS_AUTOCERT
value: "false"
- name: DRONE_DATABASE_DRIVER
value: "postgres"
- name: DRONE_DATABASE_DATASOURCE
value: "postgres://drone:drone@drone-db.default:5432/postgres?sslmode=disable"
ports:
- name: http
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: drone-db
labels:
name: drone-db
spec:
selector:
role: service
add: drone-db
clusterIP: None
ports:
- port: 5432
targetPort: postgres
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: drone-db
spec:
storageClassName: general
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: drone-db
spec:
replicas: 1
selector:
matchLabels:
role: service
add: drone-db
template:
metadata:
labels:
role: service
add: drone-db
spec:
nodeSelector:
role: general
containers:
- name: postgres
image: postgres:9.6-alpine
env:
- name: POSTGRES_USER
value: "drone"
- name: POSTGRES_PASSWORD
value: "drone"
- name: POSTGRES_DB
value: "drone"
ports:
- name: postgres
containerPort: 5432
volumeMounts:
- name: postgres
mountPath: /var/lib/postgres
volumes:
- name: postgres
persistentVolumeClaim:
claimName: drone-db
There are three pipelines for demonstrate the problem:
kind: pipeline
name: mongo
workspace:
base: /tmp
path: "."
volumes:
- name: mongo
temp: {}
services:
- name: mongo
image: mongo:3.6
ports:
- 27017
volumes:
- name: mongo
path: /data
steps:
- name: sleep
image: busybox
commands:
- echo "Waiting for start"
- sleep 30
- name: check-dns
image: alpine
commands:
- apk add -U bind-tools
- host mongo
- name: connect
image: mongo:3.6
commands:
- mongo --host mongo --eval 'db.stats()'
---
kind: pipeline
name: redis
workspace:
base: /tmp
path: "."
volumes:
- name: redis
temp: {}
services:
- name: redis
image: redis:4
ports:
- 6379
volumes:
- name: redis
path: /data
steps:
- name: sleep
image: busybox
commands:
- echo "Waiting for start"
- sleep 30
- name: check-dns
image: alpine
commands:
- apk add -U bind-tools
- host redis
- name: connect
image: redis:4
commands:
- redis-cli -h redis keys '*'
---
kind: pipeline
name: postgres
workspace:
base: /tmp
path: "."
volumes:
- name: postgres
temp: {}
services:
- name: postgres
image: postgres:9.6-alpine
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
ports:
- 5432
volumes:
- name: postgres
path: /var/lib/postgres
steps:
- name: sleep
image: busybox
commands:
- echo "Waiting for start"
- sleep 30
- name: check-dns
image: alpine
commands:
- apk add -U bind-tools
- host postgres
- name: connect
image: postgres:9.6-alpine
commands:
- echo "Must be auth error, but connection error"
- psql -h postgres test test -c 'select * from pg_catalog.pg_config;'
This is not work. All pipelines failed on connection issue.
Parsed logs of all three services below.
Mongo:
2018-12-20T20:54:46.316+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=kacb4tdn8osfdjasmm6uk5u54qezjhpb
2018-12-20T20:54:46.316+0000 I CONTROL [initandlisten] db version v3.6.9
2018-12-20T20:54:46.316+0000 I CONTROL [initandlisten] git version: 167861a164723168adfaaa866f310cb94010428f
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0f 25 May 2017
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] allocator: tcmalloc
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] modules: none
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] build environment:
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] distmod: debian92
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] distarch: x86_64
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] target_arch: x86_64
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true } }
2018-12-20T20:54:46.317+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Permission denied
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] now exiting
2018-12-20T20:54:46.317+0000 I CONTROL [initandlisten] shutting down with code:48
Redis:
1:C 20 Dec 2018 21:00:31.634 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 20 Dec 2018 21:00:31.634 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 20 Dec 2018 21:00:31.634 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 20 Dec 2018 21:00:31.638 * Running mode=standalone, port=6379.
1:M 20 Dec 2018 21:00:31.638 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 20 Dec 2018 21:00:31.638 # Server initialized
1:M 20 Dec 2018 21:00:31.638 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 20 Dec 2018 21:00:31.638 * Ready to accept connections
Postgres:
The files belonging to this database system will be owned by user "test".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found performing post-bootstrap initialization ... No usable system locales were found. Use the option "--debug" to see details. ok
syncing data to disk ... ok
Success. You can now start the database server using: pg_ctl -D /var/lib/postgresql/data -l logfile start
WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
waiting for server to start....
LOG: database system was shut down at 2018-12-21 19:34:18 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* waiting for server to shut down...
LOG: received fast shutdown request
LOG: aborting any active transactions.
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
done server stopped PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2018-12-21 19:34:20 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
Mongo was shut down immediately, but icon in web still green.
After fail on third step, logs of redis and postgres are lost from web interface (but mongo not).
P.S. I very want to use this setup and ready to live with many issues (e.g. my problems with plugins/ecr
or interface bugs), but this instrument must work for my simple cases. :-/