-
Install Docker on your development machine.
-
Install kubectl
-
Sign-up for an IBM Cloud account, or login to your existing account.
-
Create a new IBM Cloud Kubernetes Service (IKS) Free or Standard cluster with Ubuntu worker nodes, or use an existing cluster.
-
Install IBM Cloud CLI
-
Log into your IBM Cloud account using ibmcloud CLI
$ ibmcloud login
- Install IBM Cloud Container Regsitry plugin
$ ibmcloud plugin install container-registry -r 'IBM Cloud'
- Log into IBM Cloud Container Registry
$ ibmcloud cr login
- Create a new container registry namespace
$ ibmcloud cr namespace-add dotnet
- Install IBM Cloud Kubernetes service plugin
$ ibmcloud plugin install container-service -r 'IBM Cloud'
- Initialize IBM Cloud Kubernetes service plugin
$ ibmcloud ks init
- Download IKS cluster config and set kubectl context
$ eval $(ibmcloud ks cluster-config <your-iks-cluster-name> | tail -2 | head -1)
- Verify kubectl is set to use your IKS cluster
$ kubectl config current-context
Get .Net Core application sample code from a public git repo. Create a Dockerfile to build the container image using the sample application files and upload the image to IBM Container Registry. Finally, to validate run a Pod in IKS cluster using the container image hosted on ICR.
- Download sample code
$ git clone https://github.com/dotnet/dotnet-docker/
$ cd dotnet-docker/samples/dotnetapp
- This dotnetapp sample includes various Dockerfiles to build container images for different platforms. Modify Dockerfile to use
bionic
tag to build a container image to run on Ubuntu 18.04 worker nodes.
$ sed 's/:2.2/:2.2-bionic/g' Dockerfile > Dockerfile.bionic
- Build container image
$ docker build --pull -t dotnetapp:bionic -f Dockerfile.bionic .
- Validate the container image works
$ docker run --rm -it dotnetapp:bionic Hello .NET Core from Bionic
- Tag and upload container image to IBM Cloud Container Registry
$ docker tag dotnetapp:bionic us.icr.io/dotnet/dotnetapp:bionic
$ docker push us.icr.io/dotnet/dotnetapp:bionic
- Validate container image hosted on IBM Cloud Container Registry works
$ docker run --rm -it us.icr.io/dotnet/dotnetapp:bionic Hello .NET Core from Bionic
Using kubectl run a new pod created from the container image uploaded to ICR. Terminate the pod after execution is complete.
$ kubectl run -it dotnetcoreapp --rm --generator=run-pod/v1 --image=us.icr.io/dotnet/dotnetapp:bionic -- Hello from .Net Core on bionic 2>/dev/null
This demonstrates that a .Net Core application can run successfully in IBM Cloud.