Setting up external access to a pod in a cluster
Stackland allows users to run their own applications in a cluster and create external access to them. In this guide, we will show you an example of creating external access to an HTML page in a cluster.
Getting started
-
If the project does not exist yet, create it:
kubectl create namespace <project_name>. -
Select a lin for external access, e.g.,
test.<cluster domain>.You can get the cluster domain using
kubectl get platformenvironments main -o jsonpath='{.status.clusterDomain}', if required.
How to create external access
Step 1: Create an ingress resource
-
Create a file of the
Ingressresource, e.g., using thetouch ingress.yamlcommand. -
Open the file and paste the configuration below into it:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: cert-manager.io/cluster-issuer: stackland-default name: test-stackland-ingress namespace: <project name> spec: ingressClassName: stackland-default rules: - host: <external link> http: paths: - backend: service: name: test-stackland-service port: number: 5556 path: / pathType: Prefix tls: - hosts: - <external link> secretName: test-stackland-tls -
Provide the following in the parameter:
metadata.namespace: Project name.spec.rules[0].host: External access link.spec.tls[0].hosts[0]: External access link.
-
Apply the
kubectl apply -f ingress.yamlmanifest.
Step 2: Create an HTML page
-
Create a file of the
ConfigMapresource, e.g., using thetouch configmap.yamlcommand. -
Open the file and paste the configuration below into it:
apiVersion: v1 data: index.html: "<!DOCTYPE html>\n<html>\n<head>\n <title>Stackland test</title>\n <meta charSet=\"UTF-8\"/>\n</head>\n<body>\n <h1>Stackland external access test</h1>\n <p>This page is used to test external access to Stackland</p>\n</body>\n</html>\n" kind: ConfigMap metadata: name: test-stackland-html namespace: <project name> -
Provide the project name in the
metadata.namespaceparameter. -
Apply the manifest:
kubectl apply -f configmap.yaml.
Step 3: Create a deployment resource for the HTML page
-
Create a file of the
Deploymentresource, e.g., using thetouch deployment.yamlcommand. -
Open the file and paste the configuration below into it:
apiVersion: apps/v1 kind: Deployment metadata: name: test-stackland namespace: <project name> spec: replicas: 1 selector: matchLabels: app: test-stackland-service template: metadata: labels: app: test-stackland-service spec: containers: - image: nginx:alpine name: nginx ports: - containerPort: 80 volumeMounts: - mountPath: /usr/share/nginx/html name: html volumes: - configMap: name: test-stackland-html name: html -
Provide the project name in the
metadata.namespaceparameter. -
Apply the manifest:
kubectl apply -f deployment.yaml.
Step 4: Create a service resource for the HTML page
-
Create a file of the
Serviceresource, e.g., using thetouch service.yamlcommand. -
Open the file and paste the configuration below into it:
apiVersion: v1 kind: Service metadata: name: test-stackland-service namespace: <project name> spec: ports: - port: 5556 targetPort: 80 selector: app: test-stackland-service -
Provide the project name in the
metadata.namespaceparameter. -
Apply the manifest:
kubectl apply -f service.yaml.
Step 5: Test access
Use your web browser to open the external access link you selected. You should see the test HTML page there.