Skip to content

Instantly share code, notes, and snippets.

@bells17
Last active September 25, 2019 06:37
Show Gist options
  • Save bells17/7b0294bd0f4a4e80a377830b602cc1e6 to your computer and use it in GitHub Desktop.
Save bells17/7b0294bd0f4a4e80a377830b602cc1e6 to your computer and use it in GitHub Desktop.

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#container-v1-core にある

ports

List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network. Cannot be updated.

の確認

$ kubectl apply -f test-ports.yaml
deployment.apps/test-ports created
service/test-ports created

$ kubectl get svc test-ports
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE
test-ports   ClusterIP   10.43.247.19   <none>        8081/TCP,8080/TCP   24s
$ curl 10.43.247.19:8080
8080 server
$ curl 10.43.247.19:8081
8081 server

確かに ports で開けてようがなかろうがアクセスできるみたい

apiVersion: apps/v1
kind: Deployment
metadata:
name: test-ports
spec:
selector:
matchLabels:
app: test-ports
replicas: 1
template:
metadata:
labels:
app: test-ports
spec:
containers:
- name: "8080"
image: alpine
command: ["/bin/sh", "-c", "apk add wget; wget https://github.com/bells17/echo-server/releases/download/v0.0.1/echo-server-linux-amd64; chmod u+x echo-server-linux-amd64; ./echo-server-linux-amd64 --port=8080 --message='8080 server\n'"]
ports:
- containerPort: 8081
name: healthz
protocol: TCP
- name: "8081"
image: alpine
command: ["/bin/sh", "-c", "apk add wget; wget https://github.com/bells17/echo-server/releases/download/v0.0.1/echo-server-linux-amd64; chmod u+x echo-server-linux-amd64; ./echo-server-linux-amd64 --port=8081 --message='8081 server\n'"]
---
apiVersion: v1
kind: Service
metadata:
name: test-ports
spec:
ports:
- port: 8081
name: "8081"
protocol: TCP
targetPort: 8081
- port: 8080
name: "8080"
protocol: TCP
targetPort: 8080
selector:
app: test-ports
sessionAffinity: None
type: ClusterIP
https://kubernetes.slack.com/archives/C0QKVN230/p1569391863028900
で ports に影響ありそうなところを教えてもらった
おまけ
https://kubernetes.io/docs/search/?q=%22named+port%22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment