Kubernetes jenkins - Permission denied

2/14/2021

I have installed kubernetes cluster thus I have a deployment file for jenkins.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        ports:
          - name: http-port
            containerPort: 8080
          - name: jnlp-port
            containerPort: 50000
        volumeMounts:
          - name: jenkins-vol
            mountPath: /var/jenkins_vol
            spec:
      volumes:
        - name: jenkins-vol
          emptyDir: {}

The only thing I need is to install kubernetes client (Kubectl) through curl request. The problem is that when I enter the pod and create curl request it returns Permission denied

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.2/bin/linux/amd64/kubectl
Warning: Failed to create the file kubectl: Permission denied
-- Ilia Hanev
jenkins
kubernetes

1 Answer

2/14/2021

Try adding securityContext in your deployment

spec:
  securityContext:
    runAsUser: 0

If this doesnt work,( your jenkins deployment is failing or some other issue), then when you enter the pod ( pod exec) check what user is it by running id or whoami

-- Kiran
Source: StackOverflow