Updated: 03 September 2023

Deploy a Kubernetes App on ICP

You can do any of the following

Deploy a an App to the Cluster

We can use kubectl to deploy an application to ICP

Configure kubectl

We can use the configuration code from ICP as follows

Terminal window
1
kubectl config set-cluster cluster.local --server=https://10.0.0.1:8001 --insecure-skip-tls-verify=true
2
kubectl config set-context cluster.local-context --cluster=cluster.local
3
kubectl config set-credentials admin --token=<YOUR TOKEN>kubectl config set-context cluster.local-context --user=admin --namespace=cert-manager
4
kubectl config use-context cluster.local-context

Deploy the Application

DeveloperWorks Article on Doing this

Then we need to get our deployment manifest file and run the deploy command, we will need the following

  • Deployment manifest
  • Service manifest
  • Ingress manifest

We need the service to expose our app on a port, and an ingress rule to expose that externally

deployment.yaml

1
apiVersion: extensions/v1beta1
2
kind: Deployment
3
metadata:
4
name: express-basic
5
spec:
6
replicas: 1
7
template:
8
metadata:
9
labels:
10
app: express-basic
11
version: v2
12
spec:
13
containers:
14
- image: nabeelvalley/express-basic
15
name: express-basic
16
ports:
17
- containerPort: 8080

service.yaml

1
apiVersion: v1
2
kind: Service
3
metadata:
4
name: express-basic
5
labels:
6
app: express-basic
7
version: v2
8
spec:
9
ports:
10
- port: 8080
11
name: http
12
selector:
13
app: express-basic
14
version: v2

ingress.yaml

1
apiVersion: extensions/v1beta1
2
kind: Ingress
3
metadata:
4
name: express-basic-ingress
5
spec:
6
rules:
7
- http:
8
paths:
9
- path: /
10
backend:
11
serviceName: express-basic
12
servicePort: 8080
13
- path: /test
14
backend:
15
serviceName: express-basic
16
servicePort: 8080

We can then deploy these resource definitions on our cluster with

Terminal window
1
kubectl apply -f deployment.yaml
2
kubectl apply -f service.yaml
3
kubectl apply -f ingress.yaml

Alternatively we can include all three in a single file and apply it as follows

deploy.yaml

1
apiVersion: v1
2
kind: Service
3
metadata:
4
name: express-basic
5
labels:
6
app: express-basic
7
version: v2
8
spec:
9
ports:
10
- port: 8080
11
name: http
12
selector:
13
app: express-basic
14
version: v2
15
16
---
17
apiVersion: extensions/v1beta1
18
kind: Deployment
19
metadata:
20
name: express-basic
21
spec:
22
replicas: 1
23
template:
24
metadata:
25
labels:
26
app: express-basic
27
version: v2
28
spec:
29
containers:
30
- image: nabeelvalley/express-basic
31
name: express-basic
32
ports:
33
- containerPort: 8080
34
---
35
apiVersion: extensions/v1beta1
36
kind: Ingress
37
metadata:
38
name: express-basic-ingress
39
spec:
40
rules:
41
- http:
42
paths:
43
- path: /
44
backend:
45
serviceName: express-basic
46
servicePort: 8080
47
- path: /test
48
backend:
49
serviceName: express-basic
50
servicePort: 8080
51
---
Terminal window
1
kubectl apply -f deploy.yaml