Home > Blockchain >  powershell pod failing in kubernetes cluster
powershell pod failing in kubernetes cluster

Time:10-13

I need to run powershell as an container in kubernetes

I am using following deployment file sample.yaml

apiVersion: v1
kind: Pod
metadata:
  name: powershell
spec:
  containers:
  - name: powershell
    image: mcr.microsoft.com/powershell:latest

When I run kubectl apply -f sample.yaml

I get the following error on kubectl get pods

powershell        0/1     CrashLoopBackOff   3 (50s ago)   92s

I did check the log kubectl logs powershell

PowerShell 7.2.6
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> ←[?1h

But when i run same image as a docker container with following command its working

docker run --rm -it mcr.microsoft.com/powershell:latest

CodePudding user response:

The docker run the same image by allocating the interactive shell by using flag -it. So that's why the to container keeps running until you exit the command.

To achieve similar in Kubernetes you can use run command.

kubectl run -i --rm --tty power --image=mcr.microsoft.com/powershell:latest

interactive-bash-pod-within-a-kubernetes

CodePudding user response:

If you want to keep a container for running, you should write like this yaml..

apiVersion: v1
kind: Pod
metadata:
  name: powershell
spec:
  containers:
  - name: powershell
    image: mcr.microsoft.com/powershell:latest
    command: ["pwsh"]
    args: ["-Command", "Start-Sleep", "3600"]

[root@master1 ~]# kubectl get pod powershell
NAME         READY   STATUS    RESTARTS   AGE
powershell   1/1     Running   0          3m32s
[root@master1 ~]# kubectl exec -it powershell -- pwsh
PowerShell 7.2.6
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> date
Thu Oct 13 12:50:24 PM UTC 2022
PS />

  • Related