Creating a NodePort Service in OKS
A NodePort is a type of Kubernetes service that exposes your application on all worker nodes, through a specified TCP/UDP port allowing external access to the service.
You can create a NodePort service using OKS.
Creating a NodePort Service
Kubernetes allows you to open ports within the following range: |
To create a NodePort service, you need to attach the required annotations to your manifests.
Service manifests are the YAML or JSON configuration files defining the desired state of a Service
resource. They describe how a service is exposed within your OKS cluster, with details such as:
-
The service type (ClusterIP, NodePort, LoadBalancer),
-
The ports that the service should expose,
-
The selector for the pods that the service targets,
-
All relevant annotations or labels.
The following example creates a KeyDB installation accessible on port 30379
, from the 1.2.3.4/32
IP only.
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: keydb-deployment
name: keydb-deployment
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: keydb-deployment
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: keydb-deployment
spec:
containers:
- image: eqalpha/keydb:alpine
name: keydb-container
ports:
- containerPort: 6379
resources:
requests:
cpu: 1
volumeMounts:
- name: data
mountPath: /keydb-master-data
- name: keydb-config
mountPath: /keydb-master
volumes:
- name: keydb-config
configMap:
name: my-keydb-config
- name: data
emptyDir: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: keydb-service
namespace: default
labels:
app: keydb-deployment
annotations:
service.oks.outscale.com/source-ranges: "1.2.3.4/32"
spec:
ports:
- port: 6379
targetPort: 6379
nodePort: 30379
selector:
app: keydb-deployment
type: NodePort
Using Annotations In Your NodePorts
The table below lists supported annotations for your OKS NodePort services.
Lists should be comma-separated unless specified otherwise. |
Annotation | Description | Default value | ||
---|---|---|---|---|
|
The list of CIDRs allowed to access the NodePort. For example:
|
None (no access) |
||
|
The list of nodes to allow external access to. For example: |
None (all worker nodes) |
Related Pages